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

[size=medium]最近在学cocos2d,刚下的1.0以上的安装包,没想到编写书中例子的时候遇到了许多cocos2d版本更新带来的问题。现将他们一一纪录下来,以备后用。

1 CCMenuItemFont的itemFromString: target: selector:方法,该方法已被deprecated。][/size]
新方法使用如下:
CCMenuItem *GameSettings = [CCMenuItemFont itemWithString:@"设置" target:self selector:nil];

[size=medium]
2 CCTransitionShrinkGrow等对象,原来均是以CCXXXTransition命名,而今变成了CCTransitionXXX。[/size]例如:
1.0版本以下 1.0版本及以上
CCShrinkGrowTransition CCTransitionShrinkGrow
CCSlideInRTransition CCTransitionSlideInR
CCSlideInRLransition CCTransitionSlideInL
[size=medium]
3 CCBitmapFontAtlas对象没用了,改称了CCLabelBMFont。[/size]
1.0版本以前的用法:
CCBitmapFontAtlas *lbScore = [CCBitmapFontAtlas bitmapFontAtlasWithString:@"Time: 0" fntFile:@"font09.fnt"];

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

[size=medium]
4 CCSpriteSheet对象也没有了,改成了CCSpriteBatchNode[/size]
1.0版本以前的用法:
CCSpriteSheet *mgr = [CCSpriteSheet spriteSheetWithFile:@"flight.png" capacity:5];

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

[size=medium]
5 CCAnimation的animationWithName方法已被deprecated,改成了animationWithSpriteFrames[/size]
原用法:
CCAnimation *animation = [CCAnimation animationWithName:@"flight" delay:0.2f];

1.0版本及以后的用法:
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];


[size=medium]
版本更新问题:
在编译这个的时候,出现了如标题中的错误[/size]

+ (id) layerWithColor:(ccColor4B)color
{
return [[[self alloc] initWithColor:color] autorelease];
}

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

11L大神给出了解决办法

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

+ (id) layerWithColor:(ccColor4B)color
{
return [[(ColorLayer*)[self alloc] initWithColor:color] autorelease];
}
[size=medium]
在新版本的cocos2d中ColorLayer更新为CCColorLayer了或者是CCLayerColor,两者是一样的。
[/size]
未完待续
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值