李華明Himi 原創,轉載務必在明顯處註明:
轉載自【黑米GameDev街區】 原文連結: http://www.himigame.com/iphone-cocos2d/423.html
CCScene 對於使用cocos2d的童鞋肯定很熟悉,那麼在使用 [[CCDirectorsharedDirector]replaceScene:<#(CCScene *)scene#>]; 對scene進行情境(CCLayout)進行切換時,cocos2d提供了一些特效進行過渡,那麼今天仔細翻開cocos2d源碼,將所有的動畫效果都測試了一遍,大概整理如下,提供大家查閱和使用吧;
因為我使用的是最新的cocos2d的1.0版本,所以一些函數方法跟之前不一樣了,所以不要感到奇怪;
由於代碼都有備忘,所以就直接上代碼了,就不詳細單獨解釋了;關於注釋的都是我的直觀體驗,推薦大家放到自己項目中,自己都看看每個的效果,這樣記憶深刻;
//觸摸事件 - 當手指從螢幕抬起時調用的方法-Himi-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{CCScene* scenec = [OtherLayout scene]; //部落格------//CCTransitionTurnOffTiles *transitionScene = [CCTransitionTurnOffTiles transitionWithDuration:3 scene:scenec];//近遠-遠近-----//CCTransitionShrinkGrow *transitionScene = [CCTransitionShrinkGrow transitionWithDuration:3 scene:scenec];//另一個layout左側進入(視覺感覺是螢幕右移)//CCTransitionSlideInL *transitionScene = [CCTransitionSlideInL transitionWithDuration:3 scene:scenec];//另一個layout右側進入(視覺感覺是螢幕左移)//CCTransitionSlideInR *transitionScene = [CCTransitionSlideInR transitionWithDuration:3 scene:scenec];//另一個layout上側進入(視覺感覺是螢幕下移)//CCTransitionSlideInT *transitionScene = [CCTransitionSlideInT transitionWithDuration:3 scene:scenec];//另一個layout下側進入(視覺感覺是螢幕上移)//CCTransitionSlideInB *transitionScene = [CCTransitionSlideInB transitionWithDuration:3 scene:scenec];//當前螢幕被分為3列,兩則下移,中間上移//CCTransitionSplitCols *transitionScene = [CCTransitionSplitCols transitionWithDuration:3 scene:scenec];//當前螢幕被分為3列,兩則左移,中間右移//CCTransitionSplitRows *transitionScene = [CCTransitionSplitRows transitionWithDuration:3 scene:scenec]; //扇形轉換-----//CCTransitionRadialCW *transitionScene = [CCTransitionRadialCW transitionWithDuration:3 scene:scenec];//平面旋轉-----//CCTransitionRotoZoom *transitionScene = [CCTransitionRotoZoom transitionWithDuration:3 scene:scenec];//近-遠-跳動------//CCTransitionJumpZoom *transitionScene = [CCTransitionJumpZoom transitionWithDuration:3 scene:scenec];//立體反轉(X軸)--(還有種從近到遠,從遠到近的感覺)--------//CCTransitionZoomFlipX *transitionScene = [CCTransitionZoomFlipX transitionWithDuration:3 scene:scenec];//立體反轉(Y軸)-(還有種從近到遠,從遠到近的感覺)-------//CCTransitionZoomFlipY *transitionScene = [CCTransitionZoomFlipY transitionWithDuration:3 scene:scenec];//立體反轉(X,Y軸)---(還有種從近到遠,從遠到近的感覺)-----//CCTransitionZoomFlipAngular *transitionScene = [CCTransitionZoomFlipAngular transitionWithDuration:3 scene:scenec];//另外一個layout左側進入覆蓋當前layout//CCTransitionMoveInL *transitionScene = [CCTransitionMoveInL transitionWithDuration:3 scene:scenec];//另外一個layout右側進入覆蓋當前layout//CCTransitionMoveInR *transitionScene = [CCTransitionMoveInR transitionWithDuration:3 scene:scenec];//另外一個layout上側進入覆蓋當前layout//CCTransitionMoveInT *transitionScene = [CCTransitionMoveInT transitionWithDuration:3 scene:scenec];//另外一個layout下側進入覆蓋當前layout//CCTransitionMoveInB *transitionScene = [CCTransitionMoveInB transitionWithDuration:3 scene:scenec];//立體反轉(X軸)--2D平面反轉,沒有遠近感//CCTransitionFlipX *transitionScene = [CCTransitionFlipX transitionWithDuration:3 scene:scenec];//立體反轉(Y軸)--2D平面反轉,沒有遠近感//CCTransitionFlipY *transitionScene = [CCTransitionFlipY transitionWithDuration:3 scene:scenec];//立體反轉(X,Y軸)--2D平面反轉,沒有遠近感//CCTransitionFlipAngular *transitionScene = [CCTransitionFlipAngular transitionWithDuration:3 scene:scenec];//實體-透明-實體(預設無顏色,可以附帶顏色)//CCTransitionFade* transitionScene = [CCTransitionFade transitionWithDuration:3 scene:scenec withColor:ccWHITE];//另外一個直接漸層覆蓋當前layout //CCTransitionCrossFade *transitionScene = [CCTransitionCrossFade transitionWithDuration:3 scene:scenec];//移動(方格狀)部落格,從左下往右上//CCTransitionFadeTR *transitionScene = [CCTransitionFadeTR transitionWithDuration:3 scene:scenec];//移動(方格狀)部落格,從右上往左下CCTransitionFadeBL *transitionScene = [CCTransitionFadeBL transitionWithDuration:3 scene:scenec];//移動(長矩形,寬度是螢幕寬)部落格,從下往上//CCTransitionFadeUp *transitionScene = [CCTransitionFadeUp transitionWithDuration:3 scene:scenec];//移動(長矩形,寬度是螢幕寬)部落格,從上往下//CCTransitionFadeDown *transitionScene = [CCTransitionFadeDown transitionWithDuration:3 scene:scenec];[[CCDirector sharedDirector] replaceScene: transitionScene];}
以上代碼Himi推薦大家自己常識運行每種特效,畢竟每個人都有不同的感覺,注釋都是我的感覺寫的,大概注釋了一下而已;
下面我來給大家介紹如何在cocos2d 1.0版本中設定豎屏顯示,因為預設是橫屏;
首先找到RootViewController.m 類(此類在1.0版本存在),然後找到宏定義的一段代碼,代碼如下:
#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
然後下面能看到cocos2d的預設代碼是設定橫屏:
return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );
如果想設定豎屏,請更改如下即可:
return (UIInterfaceOrientationIsPortrait(interfaceOrientation));
ok,今天就先介紹這裡~繼續學習~下面給出一張,部落格效果,從左下往右上的切換特效;