CCScene切换特效 以及 设置屏幕横竖屏(转)

时间:2022-11-30 07:16:02


CCScene场景切换代码:


1.//触摸事件 - 当手指从屏幕抬起时调用的方法-Himi    
2.-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
3.{
4. CCScene* scenec = [OtherLayout scene];
5. //部落格------
6. //CCTransitionTurnOffTiles *transitionScene = [CCTransitionTurnOffTiles transitionWithDuration:3 scene:scenec];
7. //近远-远近-----
8. //CCTransitionShrinkGrow *transitionScene = [CCTransitionShrinkGrow transitionWithDuration:3 scene:scenec];
9. //另一个layout左侧进入(视觉感觉是屏幕右移)
10. //CCTransitionSlideInL *transitionScene = [CCTransitionSlideInL transitionWithDuration:3 scene:scenec];
11. //另一个layout右侧进入(视觉感觉是屏幕左移)
12. //CCTransitionSlideInR *transitionScene = [CCTransitionSlideInR transitionWithDuration:3 scene:scenec];
13. //另一个layout上侧进入(视觉感觉是屏幕下移)
14. //CCTransitionSlideInT *transitionScene = [CCTransitionSlideInT transitionWithDuration:3 scene:scenec];
15. //另一个layout下侧进入(视觉感觉是屏幕上移)
16. //CCTransitionSlideInB *transitionScene = [CCTransitionSlideInB transitionWithDuration:3 scene:scenec];
17. //当前屏幕被分为3列,两则下移,中间上移
18. //CCTransitionSplitCols *transitionScene = [CCTransitionSplitCols transitionWithDuration:3 scene:scenec];
19. //当前屏幕被分为3列,两则左移,中间右移
20. //CCTransitionSplitRows *transitionScene = [CCTransitionSplitRows transitionWithDuration:3 scene:scenec];
21. //扇形转换-----
22. //CCTransitionRadialCW *transitionScene = [CCTransitionRadialCW transitionWithDuration:3 scene:scenec];
23. //平面旋转-----
24. //CCTransitionRotoZoom *transitionScene = [CCTransitionRotoZoom transitionWithDuration:3 scene:scenec];
25. //近-远-跳动------
26. //CCTransitionJumpZoom *transitionScene = [CCTransitionJumpZoom transitionWithDuration:3 scene:scenec];
27. //立体反转(X轴)--(还有种从近到远,从远到近的感觉)--------
28. //CCTransitionZoomFlipX *transitionScene = [CCTransitionZoomFlipX transitionWithDuration:3 scene:scenec];
29. //立体反转(Y轴)-(还有种从近到远,从远到近的感觉)-------
30. //CCTransitionZoomFlipY *transitionScene = [CCTransitionZoomFlipY transitionWithDuration:3 scene:scenec];
31. //立体反转(X,Y轴)---(还有种从近到远,从远到近的感觉)-----
32. //CCTransitionZoomFlipAngular *transitionScene = [CCTransitionZoomFlipAngular transitionWithDuration:3 scene:scenec];
33. //另外一个layout左侧进入覆盖当前layout
34. //CCTransitionMoveInL *transitionScene = [CCTransitionMoveInL transitionWithDuration:3 scene:scenec];
35. //另外一个layout右侧进入覆盖当前layout
36. //CCTransitionMoveInR *transitionScene = [CCTransitionMoveInR transitionWithDuration:3 scene:scenec];
37. //另外一个layout上侧进入覆盖当前layout
38. //CCTransitionMoveInT *transitionScene = [CCTransitionMoveInT transitionWithDuration:3 scene:scenec];
39. //另外一个layout下侧进入覆盖当前layout
40. //CCTransitionMoveInB *transitionScene = [CCTransitionMoveInB transitionWithDuration:3 scene:scenec];
41. //立体反转(X轴)--2D平面反转,没有远近感
42. //CCTransitionFlipX *transitionScene = [CCTransitionFlipX transitionWithDuration:3 scene:scenec];
43. //立体反转(Y轴)--2D平面反转,没有远近感
44. //CCTransitionFlipY *transitionScene = [CCTransitionFlipY transitionWithDuration:3 scene:scenec];
45. //立体反转(X,Y轴)--2D平面反转,没有远近感
46. //CCTransitionFlipAngular *transitionScene = [CCTransitionFlipAngular transitionWithDuration:3 scene:scenec];
47. //实体-透明-实体(默认无颜色,可以附带颜色)
48. //CCTransitionFade* transitionScene = [CCTransitionFade transitionWithDuration:3 scene:scenec withColor:ccWHITE];
49. //另外一个直接渐变覆盖当前layout
50. //CCTransitionCrossFade *transitionScene = [CCTransitionCrossFade transitionWithDuration:3 scene:scenec];
51. //移动(方格状)部落格,从左下往右上
52. //CCTransitionFadeTR *transitionScene = [CCTransitionFadeTR transitionWithDuration:3 scene:scenec];
53. //移动(方格状)部落格,从右上往左下
54. CCTransitionFadeBL *transitionScene = [CCTransitionFadeBL transitionWithDuration:3 scene:scenec];
55. //移动(长矩形,宽度是屏幕宽)部落格,从下往上
56. //CCTransitionFadeUp *transitionScene = [CCTransitionFadeUp transitionWithDuration:3 scene:scenec];
57. //移动(长矩形,宽度是屏幕宽)部落格,从上往下
58. //CCTransitionFadeDown *transitionScene = [CCTransitionFadeDown transitionWithDuration:3 scene:scenec];
59. [[CCDirector sharedDirector] replaceScene: transitionScene];
60.}


设置横竖屏代码


首先找到RootViewController.m 类(此类在1.0版本存在),然后找到宏定义的一段代码,代码如下:


#elif GAME_AUTOROTATION == kGameAutorotationUIViewController


然后下面能看到cocos2d的默认代码是设置横屏:


1.return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );


如果想设置竖屏,请更改如下即可:


1.return (UIInterfaceOrientationIsPortrait(interfaceOrientation));