关于CCAction方法
来源:互联网 发布:明星拼图软件 编辑:程序博客网 时间:2024/06/10 19:37
本方法再初始化的时候,加入了autorelease,因此,如果把CCAction当做对象的成员变量来使用的话,也许你在初始化一个对象的时候,分配给了该变量一块内存,但是,在程序运行的时候某一时刻,如果程序发现该内存没有被使用,将会回收此空间。所以,当你下次在使用这个成员变量指针的时候,就会引发bad access错误。为了避免此类错误,以后应避免使用某个autorelease对象指针作为自定义的对象成员变量。
例如:
自定义sprite的初始化方法中
self.bugType = bugTypes;
isOnTouch = FALSE;
isHavingBody = NO;
self.tag = kBodyTagBug;
[self setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"woniu1.png"]];
// move动画
CCAnimation *animationMove= [CCAnimation animation];
for (int i= 1; i<=4; i++) {
[animationMove addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"woniu%d.png",i]]];
}
actMove = [CCRepeatForever actionWithAction:[CCAnimate actionWithDuration:0.4 animation:animationMove restoreOriginalFrame:NO]];
// struggle动画
CCAnimation *animationStruggle = [CCAnimation animation];
for (int i = 1; i <= 11; i++) {
[animationStruggle addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"woniu_zhengzha%d.png",i]]];
}
actStruggle = [CCRepeatForever actionWithAction:[CCAnimate actionWithDuration:0.2 animation:animationStruggle restoreOriginalFrame:NO]];
// inbottle动画
CCAnimation *animationInBottle = [CCAnimation animation];
for (int i = 2; i <=3 ;i++) {
[animationInBottle addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"woniu%d.png",i]]];
}
actInBottle = [CCRepeatForever actionWithAction:[CCAnimate actionWithDuration:0.2 animation:animationInBottle restoreOriginalFrame:NO]];
actMove actStruggle actBottle已经在对象初始化的时候被初始化,我在对象初始化完毕后,立即使用了runaction:actMove,而没有使用另外两个ccaction 对象指针,在程序运行了一段时间之后,我又想使用actStruggle, 发现该指针所指的内存已经被释放,导致badaccess错误。
- 关于CCAction方法
- CCAction
- CCACTION
- CCAction
- CCAction
- CCAction详解
- 九、CCAction
- 游戏-CCAction
- CCAction类
- 九、CCAction
- 九、CCAction
- ccaction/ccanimate
- 九、CCAction
- CCAction动画
- (13) CCAction
- Cocos-2d 关于多个CCSprite精灵播放同一个CCAction动画问题
- Cocos-2d 关于多个CCSprite精灵播放同一个CCAction动画问题
- cocod2d-x--关于场景切换,CCAction未执行完,仍持有引用造成内存泄漏
- 关于QT assistant在windows下单独运行无内容的解决办法
- VC++ 链接库(一)基本概念
- 【条款12】Copy all parts of an object
- 汇编知识总结--第一部分
- 深入理解Javascript闭包
- 关于CCAction方法
- 摆脱“悬赏”束缚,知识交易平台朝电商领域进发
- MYSQL 常见错误
- 汇编知识总结--第二部分(判断指令是否正确)
- 构建基本的嵌入式Linux根文件系统
- 创建数据链路
- Class.forName("xxx.xx")详解
- android跑马灯实现
- 10004 - Bicoloring