Home and Blog button

Pages

Introduction

Welcome To my Blog !!
This is a blog where you can get some knowledge that i have learned and been using. Sharing is gaining pals. So Happy Sharing and don't forget to follow and link my blog with yours! Thanks.
Happy Programming!!

Tuesday, June 28, 2011

Using CCLabelBMFont instead of ALLabelAtlas after Upgrading Cocos2d to 0.99.5 or higher!


Hi pals,

I am thinking of posting some more articles in these days so that I can help lot of people with my shared knowledge. There is always a busy time in office and rest time in weekends. However in some weekends I will be writing some useful posts. Hope it would be helpful to some guys out there.

In this post, I am going to write about the ALLabelAtlas and CCLabelBMFont.

ALLabelAtlas:

This is open source project created by indeedo during the cocos2d version 0.99.4. It has a Label Creator tool which will create a “myfont.png” image file of selected font and corresponding “myfont.plist” property list file. The plist file consists of all the co – ordinate information of the alphabet images. You can add shadows and effect in the Bitmap Font created using above Label Creator Tool. The ALLabelAtlas has .h and .m source files while will now create a label using above bitmap font created. This works well with the cocos2d version 0.99.4 and below. But problem arises when you upgrade your cocos2d game engine.

It is because the source files of base class are modified. And our creator of ALLabelAtlas doesn’t seem to have time to upgrade his code. So, we will be now using CCLabelBMFont instead of ALLabelAtlas.

CCLabelBMFont:

It is a Bitmap Font Label which is built in cocos2d version 0.99.5 or higher. It uses the bitmap font file (*.fnt) file to create a label. Similar to above tool, there are varieties of tool available which will create “myfont.fnt” file and corresponding “myfont.png” image. There are different versions of such tool. They are:
  1. Heiro Tool. (Download)
  2. BMFont tool for windows. (Download)
Among above all, Heiro tool is preferred one. Because of following properties:






  1. It is java version tool which can be run in both Mac OS and Windows OS.
  2. It supports shadows effects, gradient effects and others.
  3. It is however little buggy which cause it to show some weird behaviors.
  4. To know more about how to use Heiro Tool efficiently and troubleshoot it, please visit this article by Mr Steffen. He is writer of book “Learn iPhone and iPad cocos2d game development”.


After you successfully created the “myfont.fnt” and “myfont.png” files, just import them to resources and create new Label by following way:

CCLabelBMFont *newGameLabel = [[CCLabelBMFont alloc] initWithString:@”NEW GAME” fntFile:@”myfont.fnt”];
newGameLabel.position = ccp(winSize.width/2, winSize.height / 2);
[self addChild: newGameLabel];
[newGameLabel release];

Which one is Better and Why?

Among the above two the CCLabelBMFont are more better than ALLabelAtlas due to following reasons.
  1. The ALLabelAtlas is outdated when new version of cocos2d is used (0.99.5 or above)
  2. One key problem with ALLabelAtlas is that, the label created using it doesn't positioned well. In order words sprites created by these doesn't have fixed and defined anchor points so that you can align it in your own way. To position these labels you need to do hard coding, which is bad practice.
  3. The position of CCLabelBMFont are well positioned and easy to manipulate in the screen.
Draw Back of CCLabelBMFont over ALLabelAtlas:

  1. When drawing a large line of text using CCLabelBMFont, these labels are slower than ALLabelAtlas, which can create nightmare for a developer to overcome it. To print line more than 60, the app freezes for more than two seconds which is very annoying. 
  2. Goto Solution for this problem here.

I hope above information helps some guys there who are stuck with using Bitmap fonts and might be searching to use which one of bitmap fonts. If anyone has any suggestions, feel not write please leave comment below.

Happy sharing and thanks for reading.

No comments:

Post a Comment

Search This Blog