cocos2d學習筆記(四)CCLabelTTF和CCLabelBMFont

來源:互聯網
上載者:User

當我們在遊戲中添加文字時,比如分數,金錢之類的,就需要用到CCLabelTTF或CCLabelBMFont了


CCLabelTTF只支援系統的字型,或者你自行添加的ttf字型,用法:


CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];


CCLabelBMFont是CCSpriteBatchNode的子類,可以理解為一個font atlas,用法


CCLabelBMFont *gameBeginLabel =          [CCLabelBMFont labelWithString:@"Game Start" fntFile:@"SpaceVikingFont.fnt"];


因為CCLabelTTF和CCLabelBMFont都是CCNode的子類,所以他們也可以通過runAction:做一些動畫效果:


[gameBeginLabel setPosition:ccp(screenSize.width/2,screenSize.height/2)];          // 2        

[self addChild:gameBeginLabel];                                    // 3        

id labelAction = [CCSpawn actions:                          

                              [CCScaleBy actionWithDuration:2.0f scale:4],                           

                              [CCFadeOut actionWithDuration:2.0f],                           

                             nil];                                          // 4         

[gameBeginLabel runAction:labelAction];


另外,他們還有anchor point的概念:

[gameBeginLabel setAnchorPoint: ccp(0.5f, 0.5f)];//預設

錨點範圍為(0,0)到(1,1)之間,預設是(0.5,0.5),對象在變化的時候會以錨點為基準進行,如果錨點設為(0,0),那麼上面放大的動畫會朝向右上的位置進行放大

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.