`
zjjzmw1
  • 浏览: 1353602 次
  • 性别: Icon_minigender_1
  • 来自: 开封
社区版块
存档分类
最新评论

cocos2d 2.0以后的修改

 
阅读更多

1.所有sprite的创建改为sprite::cretae

2.没有了CCMutableArray 全改为CCArray

3. LAYER_NODE_FUNC 改为CREATE_FUNC

4。setisTouchEnabled 改为 setTouchEnabled

5   CCRepeatForever::actionWithAction 以及所有Action 都用create方法创建

6。addFrameWithTexture 改为 addSprieFrameWithTexture

7 update(CCTime dt) 改为 update(float dt)

8 CCSpriteSheet 改为 CCSpriteBatchNode

CCSpriteSheet *mgr = [CCSpriteSheet spriteSheetWithFile:@"flight.png" capacity:5];
        [self addChild:mgr z:0 tag:4];

CCSpriteBatchNode *mgr = [CCSpriteBatchNode batchNodeWithFile:@"flight.png" capacity:5];
        [self addChild:mgr z:0 tag:4];

9 CCBitmapFontAtlas 改为CCLabelBMFont

 

CCBitmapFontAtlas *lbScore = [CCBitmapFontAtlas bitmapFontAtlasWithString:@"Time: 0" fntFile:@"font09.fnt"];

CCLabelBMFont *lbLife = [CCLabelBMFont labelWithString:@"3" fntFile:@"font09.fnt"];

 

10 转换场景的时候全部以CCTransition 开头了。

[CCTransitionMoveInL transitionWithDuration:1.2f scene:sc]];

 11  CCMenuItemFont的itemFromString: target: selector:方法,该方法已被deprecated。] 
新方法使用如下: 

Java代码  收藏代码
  1. CCMenuItem *GameSettings = [CCMenuItemFont itemWithString:@"设置" target:self selector:nil]; 

  CCAnimation的animationWithName方法已被deprecated,改成了animationWithSpriteFrames 
原用法: 

Java代码  收藏代码
  1. CCAnimation *animation = [CCAnimation animationWithName:@"flight" delay:0.2f];  

1.0版本及以后的用法: 
Java代码  收藏代码
  1. CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:@"flight.png"];  
  2. CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:texture rect:CGRectMake(00, texture.contentSize.width, texture.contentSize.height)];  
  3. NSArray *array = [[NSArray alloc] initWithObjects:frame, nil];  
  4. CCAnimation *animation = [CCAnimation animationWithSpriteFrames:array delay:0.2f];  
CCAnimation的addFrameWithTexture方法已被deprecated,改成了addSpriteFrameWithTextur
e ,用法和之前一样。
 
CCTouchDispatcher 在 1.0 时是一个 Singleton, 但在2.0 被放进入CCDirector, 
所以本来写成 

[CCTouchDispatcher sharedDispatcher]

现在要写成

 

[[CCDirector sharedDirector] touchDispatcher]


版本更新问题: 
在编译这个的时候,出现了如标题中的错误 
+ (id) layerWithColor:(ccColor4B)color 

        return [[[self alloc] initWithColor:color] autorelease]; 


刚开始是搜索的错误,找了一大堆的英文的解决办法,包括那个大名鼎鼎的啥米溢出论坛,但是没结果,后来看到这个论坛的朋友给出了结果,觉得还是同胞亲哪。 

11L大神给出了解决办法 

在[self alloc]前面加上(ColorLayer*),如下: 
+ (id) layerWithColor:(ccColor4B)color 

        return [[(ColorLayer*)[self alloc] initWithColor:color] autorelease]; 

在新版本的cocos2d中ColorLayer更新为CCColorLayer了或者是CCLayerColor,两者是一样的。

7     CCQuadParticleSystem变成了CCParticleSystemQuad。
 还有横竖屏问题,代码没有解决,只是在summary 中找到了,把Protrait 选中就行了。
 

暂时想到这么多,以后遇见了,再添加。 。。。

 //ios 横竖屏幕 只是能保证可以切换不能保证默认是上面情况。
-(BOOL)shouldAutorotate
{
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape; //UIInterfaceOrientationMaskLandscape、UIInterfaceOrientationMaskAll、UIInterfaceOrientationMaskAllButUpsideDown
//    UIInterfaceOrientationMaskLandscape  支持左右横屏
//    UIInterfaceOrientationMaskAll  支持四个方向旋转
//    UIInterfaceOrientationMaskAllButUpsideDown 支持除了UpsideDown以外的旋转
}
//考虑到兼容低版本,最好加上:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

{
    return YES;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics