您的位置:首页 > 移动开发 > Cocos引擎

cocos2d 1.0及以上版本与0.xx版本某些类的变化

2012-12-28 14:24 375 查看
1  CCMenuItemFont的itemFromString: target: selector:方法,该方法已被deprecated。] 
新方法使用如下: 

Java代码  



CCMenuItem *GameSettings = [CCMenuItemFont itemWithString:@"设置" target:self selector:nil];  

2  CCTransitionShrinkGrow等对象,原来均是以CCXXXTransition命名,而今变成了CCTransitionXXX。例如: 
      1.0版本以下                           1.0版本及以上 
CCShrinkGrowTransition       CCTransitionShrinkGrow 
CCSlideInRTransition             CCTransitionSlideInR 
CCSlideInRLransition              CCTransitionSlideInL 

3   CCBitmapFontAtlas对象没用了,改称了CCLabelBMFont。 
1.0版本以前的用法: 

Java代码  



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

1.0版本及以后的用法: 

Java代码  



CCLabelBMFont *lbScore = [CCLabelBMFont labelWithString:@"Time: 0" fntFile:@"font09.fnt"];  

4  CCSpriteSheet对象也没有了,改成了CCSpriteBatchNode 
1.0版本以前的用法: 

Java代码  



CCSpriteSheet *mgr = [CCSpriteSheet spriteSheetWithFile:@"flight.png" capacity:5];  

1.0版本及以后的用法: 

Java代码  



CCSpriteBatchNode *mgr = [CCSpriteBatchNode batchNodeWithFile:@"flight.png" capacity:5];  

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

Java代码  



CCAnimation *animation = [CCAnimation animationWithName:@"flight" delay:0.2f];  

1.0版本及以后的用法: 

Java代码  



CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:@"flight.png"];  

CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:texture rect:CGRectMake(0, 0, texture.contentSize.width, texture.contentSize.height)];  

NSArray *array = [[NSArray alloc] initWithObjects:frame, nil];  

CCAnimation *animation = [CCAnimation animationWithSpriteFrames:array delay:0.2f];  

版本更新问题: 

在编译这个的时候,出现了如标题中的错误

Java代码  



+ (id) layerWithColor:(ccColor4B)color  

{  

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

}  

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

11L大神给出了解决办法 

在[self alloc]前面加上(ColorLayer*),如下:

Java代码  



+ (id) layerWithColor:(ccColor4B)color  

{  

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

}  

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

转载自:  http://lizi07.iteye.com/blog/1517652
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: