我有以下代碼:EXC_BAD_ACCESS在IPhone的Cocos2D
-(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改變動畫按鈕:@「攻擊」 forTime :1];),我從「currentAction.isDone」行中獲得一個EXC_BAD_ACCESS錯誤,下次調用該函數時(遊戲杆將調用changeAnimation嘗試將動畫更改爲「運行」或「空閒」,但是我首先要讓攻擊動畫完成)。任何想法爲什麼我得到這個? currentAction在我的類中聲明。
編輯:除了getter之外,在類的其餘部分沒有任何與currentAction交互的東西。它的聲明在.h(CCAction * surrentAction)中。我需要初始化它嗎?我認爲runAction的返回值就足夠了?反正,當我運行調試器時,它不是零,並分配給正確的操作。
感謝,
戴夫
編輯: 我結束了創建時「攻擊」調用該改變currentAnimation函數序列,所以我回避這個問題。仍然不知道發生了什麼。 這裏的,如果你有興趣的答案: Other Post
真的需要看到班上其他同學 - 在那裏,你是如何定義currentAction以及如何互動它來回答。 – heckj 2010-07-18 18:30:03
@heckj:請參閱編輯問題,其他內容?謝謝! – 2010-07-18 18:35:06
猜測它與錯誤無關,但應該在條件中使用isEqualToString:。 – user123444555621 2010-07-18 20:53:19