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

来源:互联网 发布:mac有程序阻止关机 编辑:程序博客网 时间:2024/06/16 05:39
1  CCMenuItemFont的itemFromString: target: selector:方法,该方法已被deprecated。] 
新方法使用如下: 
Java代码  收藏代码
  1. 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代码  收藏代码
  1. CCBitmapFontAtlas *lbScore = [CCBitmapFontAtlas bitmapFontAtlasWithString:@"Time: 0" fntFile:@"font09.fnt"];  

1.0版本及以后的用法: 
Java代码  收藏代码
  1. CCLabelBMFont *lbScore = [CCLabelBMFont labelWithString:@"Time: 0" fntFile:@"font09.fnt"];  


4  CCSpriteSheet对象也没有了,改成了CCSpriteBatchNode
 
1.0版本以前的用法: 
Java代码  收藏代码
  1. CCSpriteSheet *mgr = [CCSpriteSheet spriteSheetWithFile:@"flight.png" capacity:5];  

1.0版本及以后的用法: 
Java代码  收藏代码
  1. CCSpriteBatchNode *mgr = [CCSpriteBatchNode batchNodeWithFile:@"flight.png" capacity:5];  


5  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];  



版本更新问题: 
在编译这个的时候,出现了如标题中的错误
Java代码  收藏代码
  1. + (id) layerWithColor:(ccColor4B)color  
  2. {  
  3.         return [[[self alloc] initWithColor:color] autorelease];  
  4. }  


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

11L大神给出了解决办法 

在[self alloc]前面加上(ColorLayer*),如下:
Java代码  收藏代码
  1. + (id) layerWithColor:(ccColor4B)color  
  2. {  
  3.         return [[(ColorLayer*)[self alloc] initWithColor:color] autorelease];  
  4. }  

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


转载自:  http://lizi07.iteye.com/blog/1517652