【发布时间】:2010-07-18 18:18:54
【问题描述】:
我有以下代码:
-(void) changeAnimation:(NSString*)name forTime:(int) times {
if(currentAnimation != @"attack")
{
id action = [CCAnimate actionWithAnimation:[self animationByName:name]];
id repeatAction = [CCRepeat actionWithAction:action times:times];
currentAction = [self runAction:repeatAction];
lastANimation = currentAnimation;
currentAnimation = name;
}
else if(currentAction.isDone)
{
//Here is where I would change the animation
//but I commented the code for now
}
}
因此,当我运行它并单击将动画更改为“攻击”的按钮时(通过调用 [mysprite changeAnimation:@"attack" forTime:1];),我从“currentAction.isDone”中收到 EXC_BAD_ACCESS 错误" 行,下次调用该函数时(操纵杆会调用 changeAnimation 尝试将动画更改为“运行”或“空闲”,但我希望攻击动画先完成)。关于为什么我得到这个有什么想法吗? currentAction 在我的班级中声明。
编辑:除了 getter 之外,类的其余部分没有与 currentAction 交互的内容。它的声明在 .h (CCAction* surrentAction) 中。我需要初始化它吗?我认为 runAction 的返回值就足够了?无论如何,当我运行调试器时,它不是 nil,而是分配给正确的操作。
谢谢,
戴夫
编辑: 我最终在“攻击”时创建了一个序列,该序列调用了一个改变 currentAnimation 的函数,所以我避免了这个问题。仍然不知道发生了什么。 如果您有兴趣,这里是答案: Other Post
【问题讨论】:
-
真的需要看看课程的其余部分——你在哪里以及如何定义 currentAction 以及你如何与之交互来回答。
-
@heckj:看到问题中的编辑,还有什么?谢谢!
-
猜它与错误无关,但你应该使用 isEqualToString: 在你的条件。
-
@pumbaa:谢谢你这样做
标签: iphone objective-c cocos2d-iphone