SeharAfzal / cocos2d-android-1

Automatically exported from code.google.com/p/cocos2d-android-1
0 stars 0 forks source link

Working Example of Using CCBitmapFontAtlas #93

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi, 

I am looking for a simple example of how to work with CCBitmapFontAtlas. I have 
tried using something similar to the code below but I keep getting the errors I 
posted below.

I searched all over for an example of a successful implementation, but have 
been unable to find one.

public class GameLayer extends CCColorLayer
{
  protected CCBitmapFontAtlas scoreLabel;

 protected GameLayer(ccColor4B color, Context ctx)
 {
  super(color);     
  mContext = ctx;
  Context context = CCDirector.sharedDirector().getActivity();
  this.setIsTouchEnabled(true);
  CGSize winSize = CCDirector.sharedDirector().displaySize();
  scoreLabel = CCBitmapFontAtlas.bitmapFontAtlas(null, "ArnoPro24.fnt");
 }
}

I get the following in Log Cat
08-14 17:31:12.658: ERROR/AndroidRuntime(18145): Caused by: 
java.lang.NullPointerException
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
java.io.Reader.<init>(Reader.java:65)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
java.io.InputStreamReader.<init>(InputStreamReader.java:65)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
org.cocos2d.opengl.CCBitmapFontAtlas$CCBitmapFontConfiguration.parseConfigFile(C
CBitmapFontAtlas.java:162)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
org.cocos2d.opengl.CCBitmapFontAtlas$CCBitmapFontConfiguration.<init>(CCBitmapFo
ntAtlas.java:127)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
org.cocos2d.opengl.CCBitmapFontAtlas$CCBitmapFontConfiguration.configuration(CCB
itmapFontAtlas.java:120)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
org.cocos2d.opengl.CCBitmapFontAtlas.FNTConfigLoadFile(CCBitmapFontAtlas.java:52
2)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
org.cocos2d.opengl.CCBitmapFontAtlas.<init>(CCBitmapFontAtlas.java:495)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
org.cocos2d.opengl.CCBitmapFontAtlas.bitmapFontAtlas(CCBitmapFontAtlas.java:490)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
com.cgmaurer.ElementalGeorge1.GameLayer.<init>(GameLayer.java:130)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
com.cgmaurer.ElementalGeorge1.GameLayer.scene(GameLayer.java:111)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
com.cgmaurer.ElementalGeorge1.ElementalGeorge.onStart(ElementalGeorge.java:51)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1211)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
android.app.Activity.performStart(Activity.java:3822)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2760)
08-14 17:31:12.658: ERROR/AndroidRuntime(18145):     ... 11 more

Original issue reported on code.google.com by cgmau...@gmail.com on 14 Aug 2011 at 10:22

GoogleCodeExporter commented 8 years ago
I was able to resolve the problem. I needed to use one of the editors listed in 
the CCBitmapFontAtlas.java file.

Supported editors:
  - http://www.n4te.com/hiero/hiero.jnlp
  - http://slick.cokeandcode.com/demos/hiero.jnlp
  - http://www.angelcode.com/products/bmfont/

I had used the same files I used in my iOS app and they didn't work. I forget 
which app I used to create the BitmapFontAtlas, but using Heiro worked the best 
for me.

Original comment by cgmau...@gmail.com on 16 Aug 2011 at 5:20

GoogleCodeExporter commented 8 years ago
Is it possible to support the tool "GlyphDesigner" I use in Mac OS X, and I 
work it fine in cocos2d-iphone with CCLableBMFont class.

Original comment by owencyc...@gmail.com on 12 Dec 2011 at 11:58

GoogleCodeExporter commented 8 years ago
I've try and work with GlyphDesigner was successful, 
scoreLabel = CCBitmapFontAtlas.bitmapFontAtlas(null, "ArnoPro24.fnt");  
//cannot put null, instead of you should put the score's text here.

CharSequence score = "10000";
scoreLabel = CCBitmapFontAtlas.bitmapFontAtlas(score, "ArnoPro24.fnt");

Original comment by owencyc...@gmail.com on 13 Dec 2011 at 12:40