这个测试分为26个方面。
CCLayer* createAtlasLayer(int nIndex) { switch(nIndex) { case 0: return new LabelAtlasTest(); case 1: return new LabelAtlasColorTest(); case 2: return new Atlas3(); case 3: return new Atlas4(); case 4: return new Atlas5(); case 5: return new Atlas6(); case 6: return new AtlasBitmapColor(); case 7: return new AtlasFastBitmap(); case 8: return new BitmapFontMultiLine(); case 9: return new LabelsEmpty(); case 10: return new LabelBMFontHD(); case 11: return new LabelAtlasHD(); case 12: return new LabelGlyphDesigner(); // Not a label test. Should be moved to Atlas test case 13: return new Atlas1(); case 14: return new LabelTTFTest(); case 15: return new LabelTTFMultiline(); case 16: return new LabelTTFChinese(); case 17: return new LabelBMFontChinese(); case 18: return new BitmapFontMultiLineAlignment(); case 19: return new LabelTTFA8Test(); case 20: return new BMFontOneAtlas(); case 21: return new BMFontUnicode(); case 22: return new BMFontInit(); case 23: return new TTFFontInit(); case 24: return new Issue1343(); case 25: return new LabelTTFAlignment(); case 26: return new LabelBMFontBounds(); } return NULL; }部分类UML图大概是这样。。
先父类AtlasDemo进入场景时候执行的内容。
void AtlasDemo::onEnter() { CCLayer::onEnter(); CCSize s = CCDirector::sharedDirector()->getWinSize(); CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 28); addChild(label, 1); label->setPosition( ccp(s.width/2, s.height-50) ); std::string strSubtitle = subtitle(); if( ! strSubtitle.empty() ) { CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16); addChild(l, 1); l->setPosition( ccp(s.width/2, s.height-80) ); } CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(AtlasDemo::backCallback) ); CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(AtlasDemo::restartCallback) ); CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(AtlasDemo::nextCallback) ); CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); menu->setPosition( CCPointZero ); item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));; addChild(menu, 1); }
AtlasDemo仅建立2个Label菜单和3个图像菜单,功能简单,不需解释。
一、看第一个测试的子类LabelAtlasTest的构造函数。
LabelAtlasTest::LabelAtlasTest() { m_time = 0; CCLabelAtlas* label1 = CCLabelAtlas::create("123 Test", "fonts/tuffy_bold_italic-charmap.plist"); addChild(label1, 0, kTagSprite1); label1->setPosition( ccp(10,100) ); label1->setOpacity( 200 ); CCLabelAtlas *label2 = CCLabelAtlas::create("0123456789", "fonts/tuffy_bold_italic-charmap.plist"); addChild(label2, 0, kTagSprite2); label2->setPosition( ccp(10,200) ); label2->setOpacity( 32 ); schedule(schedule_selector(LabelAtlasTest::step)); }
新类CCLabelAtlas, 这个类可以用setOpacity设置透明度,32看起来很暗,几乎不能看清,200就很明显了。
新的函数schedule,每一帧执行一次,原型是
void schedule (SEL_SCHEDULE selector)
void LabelAtlasTest::step(float dt)
二、测试类LabelAtlasColorTest,这个和上级的几乎一样,仅是增加的字体颜色和淡出效果。说明了CCLabelAtlas类可以调用setColor设置字体颜色。
三、测试类Atlas3,这部分有介绍了一些好工具产生BMFonts,先记录下来,以后再学习使用。
//------------------------------------------------------------------ // // Atlas3 // // Use any of these editors to generate BMFonts: // http://glyphdesigner.71squared.com/ (Commercial, Mac OS X) // http://www.n4te.com/hiero/hiero.jnlp (Free, Java) // http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java) // http://www.angelcode.com/products/bmfont/ (Free, Windows only) // //------------------------------------------------------------------
// 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
他们分别为左下角, 中间,右上角。
困了,今天先写到这里,明天继续。