/*
* Use any of these editors to generate bitmap font atlas:
* http://www.n4te.com/hiero/hiero.jnlp
* http://slick.cokeandcode.com/demos/hiero.jnlp
* http://www.angelcode.com/products/bmfont/
*/
/**
* FileName : AtlasTest.java
* Comment : 비트맵 폰트 사용
* @version : 1.0
* @author : coolsharp
* @date : 2011. 10. 19.
*/
static class Atlas3 extends AtlasDemo {
float time;
public Atlas3() {
super();
// ColorLayer 생성
CCColorLayer col = CCColorLayer.node(ccColor4B.ccc4(128,128,128,255));
addChild(col, -10);
// Bitmap Font 생성
CCBitmapFontAtlas label1 = CCBitmapFontAtlas.bitmapFontAtlas("Test", "bitmapFontTest2.fnt");
// testing anchors
// 좌표를 설정할때 기준점 위치를 처음으로 설정
label1.setAnchorPoint(CGPoint.ccp(0,0));
addChild(label1, 0, kTagBitmapAtlas1);
CCFadeOut fade = CCFadeOut.action(1.0f);
CCFadeIn fade_in = fade.reverse();
CCSequence seq = CCSequence.actions(fade, fade_in);
CCRepeatForever repeat = CCRepeatForever.action(seq);
label1.runAction(repeat);
// VERY IMPORTANT
// color and opacity work OK because bitmapFontAltas2 loads a BMP image (not a PNG image)
// If you want to use both opacity and color, it is recommended to use NON premultiplied images like BMP images
// Of course, you can also tell XCode not to compress PNG images, but I think it doesn't work as expected
CCBitmapFontAtlas label2 = CCBitmapFontAtlas.bitmapFontAtlas("Test", "bitmapFontTest2.fnt");
// testing anchors
// 좌표를 설정할때 기준점 위치를 가운데로 설정
// 특정 객체와 거리를 표시할때 무조건 0, 0이 아닌 앵커를 기준으로 거리가 계산 됨
label2.setAnchorPoint(CGPoint.ccp(0.5f, 0.5f));
// 빨간색
label2.setColor(ccColor3B.ccRED);
addChild(label2, 0, kTagBitmapAtlas2);
label2.runAction(repeat.copy());
CCBitmapFontAtlas label3 = CCBitmapFontAtlas.bitmapFontAtlas("Test", "bitmapFontTest2.fnt");
// testing anchors
// 좌표를 설정할때 기준점 위치를 우측 끝으로 설정
label3.setAnchorPoint(CGPoint.ccp(1,1));
addChild(label3, 0, kTagBitmapAtlas3);
CGSize s = CCDirector.sharedDirector().winSize();
label1.setPosition(CGPoint.ccp(0,0));
label2.setPosition(CGPoint.ccp( s.width/2, s.height/2));
label3.setPosition(CGPoint.ccp( s.width, s.height));
schedule(new UpdateCallback() {
@Override
public void update(float d) {
step(d);
}
});
}
public void step(float dt) {
time += dt;
String string = CCFormatter.format("%2.2f Test j", time);
CCBitmapFontAtlas label1 = (CCBitmapFontAtlas) getChildByTag(kTagBitmapAtlas1);
label1.setString(string);
CCBitmapFontAtlas label2 = (CCBitmapFontAtlas) getChildByTag(kTagBitmapAtlas2);
label2.setString(string);
CCBitmapFontAtlas label3 = (CCBitmapFontAtlas) getChildByTag(kTagBitmapAtlas3);
label3.setString(string);
}
@Override
public String title() {
return "CCBitmapFontAtlas Atlas3";
}
@Override
public String subtitle() {
return "Testing alignment. Testing opacity + tint";
}
}
댓글
댓글 쓰기