Cocos2d 有用的各种方法(转)

原地址:http://blog.csdn.net/dingkun520wy/article/details/6999538


从网上收集一些有用的方法,总结一下以便以后复习查找。
内容简要:
1、改变游戏速度    2、获取当前屏幕宽高    3、创建一个layer(无贴图)
4、在cocos2d中设置横屏   5、在cocos2d中设置竖屏    6、在cocos2d中设置高清模式 AppDelegate.m
7、粒子系统用法   8、进度条   9、设置为2d
10、禁止自动锁屏
----------------------------------------------------------------------------------------------------------------------------------

//1、改变游戏速度
[[CCScheduler sharedScheduler] setTimeScale:2.0f];//设置为正常的2倍


//2、获取当前屏幕宽高
CGSize size =[[CCDirector sharedDirector]winSize];

//3、创建一个layer(无贴图)
CCLayerColor *layer =[CCLayerColor layerWithColor:ccc4(0, 0, 0, 127)];
[self addChild:layer];

//4、在cocos2d中设置横屏
return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );

//5、在cocos2d中设置竖屏
return ( UIInterfaceOrientationIsPortrait( interfaceOrientation ) );

//6、在cocos2d中设置高清模式 AppDelegate.m
[director enableRetinaDisplay:YES]


//7、粒子系统用法
//添加一个粒子特效
CCParticleSystem *tempSystem = [ARCH_OPTIMAL_PARTICLE_SYSTEM particleWithFile:@"himi.plist"];
//定义位置类型
tempSystem.positionType=kCCPositionTypeRelative;//相对模式
tempSystem.positionType=kCCPositionTypeFree;//自由模式
tempSystem.position=ccp(100,100); 
[self addChild:tempSystem];

//8、进度条
CCProgressTimer *ct=[CCProgressTimer progressWithFile:@"icon.png"];
ct.position=ccp( size.width /2 , size.height/2);
[self addChild:ct z:0 tag:90];
ct.percentage = 0; //当前进度
ct.type=kCCProgressTimerTypeHorizontalBarLR;//进度条的显示样式

kCCProgressTimerTypeRadialCCW,         扇形逆时针形式
kCCProgressTimerTypeRadialCW,          扇形顺时针形式
kCCProgressTimerTypeHorizontalBarLR,   从左往右增张的形式
kCCProgressTimerTypeHorizontalBarRL,   从右往左增张的形式
kCCProgressTimerTypeVerticalBarBT,     从下往上增张的形式
kCCProgressTimerTypeVerticalBarTB,     从上往下增张的形式

//9、设置为2d
[[CCDirector sharedDirector] setProjection:kCCDirectorProjection2D];

//10、禁止自动锁屏
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

iphone有个能判断硬件朝向的值,当你改变硬件朝向的时候有个标志位
[[UIDevice currentDevice] orientation];

猜你喜欢

转载自zhangmingwei.iteye.com/blog/1744490