【iphone遊戲開發】Iphone遊戲開發之五:遊戲情境切換,點陣字的實現和Hiero工具的利用

來源:互聯網
上載者:User

一、遊戲情境切換

在iPhone遊戲開發中,遊戲之間的情境開發中有很多動畫可以實現,具體實現的動畫如下:

 

CCTransitionRotoZoom//從大到小畫面縮小並跳動進入

CCTransitionJumpZoom//立體從左邊縮小跳動進入

CCTransitionMoveInL//從左邊移動進入右邊

CCTransitionMoveInR//從右邊移動進入左邊

CCTransitionMoveInT//從上邊移動到入下邊

CCTransitionMoveInB//從下邊移動到入上邊

CCTransitionSlideInL//從左邊移動入右邊

CCTransitionSlideInR//從右邊移動入左邊

CCTransitionSlideInT//從上邊移動入下邊

CCTransitionSlideInB//從下邊移動入上邊

CCTransitionShrinkGrow//從大到小在中間縮小進入

CCTransitionFlipX//從X軸方向立體翻轉

CCTransitionFlipY//從Y軸方向立體翻轉



CCTransitionFlipAngular//從右邊頭翻轉進入

CCTransitionZoomFlipX//從X軸方向立體跳動翻轉

CCTransitionZoomFlipY//從Y軸方向立體跳動翻轉

CCTransitionZoomFlipAngular//從右邊立體縮小翻轉進入

CCTransitionFade//從中間漸層進入

CCTransitionCrossFade//從外圍漸層進入

CCTransitionTurnOffTiles//從格子覆蓋上層進入

CCTransitionSplitCols//豎直分三個方塊切入

CCTransitionSplitRows//橫向分三個方塊切入

CCTransitionFadeTR//從左下角向右上方格子漸層進入

CCTransitionFadeBL//從右上方角向左下角格子漸層進入

CCTransitionFadeUp//從下向上漸層進入

CCTransitionFadeDown//從上向下漸層進入

 

 

上面的每個動畫都作瞭解釋,當調用的時候要寫入如下代碼:

    CCScene *sc = [CCScene node];    [sc addChild:[HelloWorld scene]];    [[CCDirector sharedDirector] replaceScene:[CCTransitionZoomFlipX transitionWithDuration:ttime  scene:sc]];

 

 

畫面中提供了二十六種情境切換的動作,我將貼上demo給大家分享。

 

二、點陣字的實現

在iPhone開發中,我們要實現不同類型的字型,不同變相的字型,我們除了用Photoshop畫好圖片載入進入之外還可以做點貼字來實現。

(1)點陣字介紹

點陣字能使用OpenGL ES將文本渲染到螢幕上。在點陣字中每個字元由一張映像表示,我們可以通過Hiero產生的點陣字精靈表來實現。Hiero的為:(http://n4te.com/hiero/hiero.jnlp),我們在windows平台還能利用BMFont(http://www.anglecode.com/products/bmfont) 從TrueType產生點陣字。它提供的功能比Hiero多。

(2)Hiero介紹

Hiero主介面

 

 

從左邊的Font裡面選擇system裡面的字型,或者可以負載檔案裡面的字型,並設定字型的大小或者黑體,斜體等,然後選擇在右邊的Effects,選擇你喜歡的,然後在Rendering設定要用的寬度和高度,之後我們可以選擇Reset Cache,設定後的如下:

 

 

然後我們點擊File的save bmfont files,如:

 

 

 

這樣我們就可以得到BMFont的檔案了,一個png的精靈表使用的圖片和一個fnt的控制檔案。

(3)如何使用CCLabelBMFont解析並顯示

 

 

在初始化裡面寫入如下代碼:

 

CCLabelTTF *label = [CCLabelTTF labelWithString:@"I'm Andy From CCLabelTTF class" fontName:@"Marker Felt" fontSize:33]; CCLabelBMFont *label1 = [CCLabelBMFont labelWithString:@"I'm Andy" fntFile:@"Andy.fnt"];       CCLabelBMFont *label2 = [CCLabelBMFont labelWithString:@"I'm Andy2" fntFile:@"Andy2.fnt"];            // ask director the the window sizeCGSize size = [[CCDirector sharedDirector] winSize];                 // position the label on the center of the screenlabel1.position =  ccp( size.width /2 , size.height/2 +60);label.position =  ccp( size.width /2 , size.height/2 );label2.position =  ccp( size.width /2 , size.height/2 -60);                       // add the label as a child to this Layer [self addChild: label1]; [self addChild: label]; [self addChild: label2];

 

這樣我們就可以得到我們像那樣模擬器的顯示結果了,這節課講了情境切換和點陣字,主要是情境的動畫實現和如何製作我們想要的點陣字。好了,這節就講到這裡啦,歡迎大家支援哈。

 附上原始碼:

http://files.cnblogs.com/huangdongcheng/SceneTransition.zip

http://files.cnblogs.com/huangdongcheng/HelloCocos.zip

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.