Cocos2d-2.0與1.0版本的一些差異
剛剛學習Cocos2d,遇到某個差異就紀錄下!
1、設定螢幕方向
V1.0中:[[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];
V2.0中:在AppDelegate中過載 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 方法
同時,Info.plist檔案中 Supported interface orientations 對應的值也要修改成想要支援的螢幕方向。
如:
Landscape (left home button)
Landscape (right home button)
Portrait (bottom home button)
Portrait (top home button)
2、
CCSpriteBatchNode *_batchNode = [CCSpriteBatchNode batchNodeWithFile:@"enemy.png" capacity:10];
V1.0中:(在2.0中不會引起程式crash,但有警告)
sprite1 =[CCSprite spriteWithBatchNode:_batchNode rect:CGRectMake(...)];
sprite2 =[[CCSprite alloc]initWithBatchNode:_batchNode rect:CGRectMake(...)];
V2.0中:
sprite1 =[CCSprite spriteWithTexture:_batchNode.texture rect:CGRectMake(...)];
sprite2 =[[CCSprite alloc]initWithTexture:_batchNode.texture rect:CGRectMake(...)];
3、
NSMutableArray *animFrames = [NSMutableArray arrayWithObjects:frame, frame1 ,nil];
V1.0中:(在2.0中不會引起程式crash,但有警告)
CCAnimation *animation = [CCAnimation animationWithFrames:animFrames delay:0.2f];
[_players runAction:[CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO]]];
V2.0中:
CCAnimation *animation = [CCAnimation animationWithSpriteFrames:animFrames delay:0.2f];
animation.restoreOriginalFrame =NO;
[_players runAction:[CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:animation]]];
4、
V1.0中:(在2.0中不會引起程式crash,但有警告)
CCMenuItemImage *menu_options = [CCMenuItemImage itemFromNormalImage:@"options.png"
selectedImage:@"options.png"
target:self
selector:@selector(go_options)];
V2.0中:
CCMenuItemImage *menu_play = [CCMenuItemImage itemWithNormalImage:@"options.png"
selectedImage:@"options.png"
target:self
selector:@selector(play_options)];
5、
V1.0中:(在2.0中不會引起程式crash,但有警告)
CCMenuItemFont *on = [CCMenuItemFont itemFromString:@"ON"];
CCMenuItemFont *off = [CCMenuItemFont itemWithString:@"OFF"];
CCMenuItemToggle * music = [CCMenuItemToggle itemWithTarget:self selector:@selector(changeMusic:) items:on,off,nil];
V2.0中:
CCMenuItemFont *on = [CCMenuItemFont itemWithString:@"ON" target:self selector:nil];
CCMenuItemFont *off = [CCMenuItemFont itemWithString:@"OFF" target:self selector:nil];
CCMenuItemToggle * music = [CCMenuItemToggle itemWithTarget:self selector:@selector(changeMusic:) items:on,off,nil];
6、
V1.0中:(在2.0中不會引起程式crash,但有警告)
EAGLView *glView = [director openGLView];
V2.0中:
CCGLView *glView = (CCGLView *)[director view];
7、類名改變
V1.0中:
CCColorLayer
V2.0中:
CCLayerColor
轉載請保留,原文連結:http://blog.csdn.net/zfpp25_/article/details/8641704
若發現有不合適或錯誤之處,還請批評指正,不勝感激。