2010-09-26 64 views
0

我在CCAnimation的runAction方法中遇到了一些問題。如果我在initWithBodyPartImage中創建了CCAnimate之後運行該命令,它將正常工作,沒有錯誤。但是,如果我在ccTouchBegan函數中調用runAction方法,則應用程序將崩潰並且沒有錯誤輸出到控制檯。所以當我從另一個函數調用runAction方法時,很難弄清楚爲什麼這個應用會崩潰。如果有人能幫助我,我非常感謝它?iPhone runAction沒有運行

-(id) initWithBodyPartImage 
{ 
    // Loading the Body Part sprite using a sprite frame name (eg the filename) 
    if ((self = [super initWithSpriteFrameName:@"align_01.png"])) 
    { 
     state = kBodyPartUnTouched; 
     // create an animation object from all the sprite animation frames 
     anim = [CCAnimation animationWithFrame:@"align_" frameCount:7 delay:0.08f]; 

     // run the animation by using the CCAnimate action 
     animate = [CCAnimate actionWithAnimation:anim]; 
     //CCRepeatForever* repeat = [CCRepeatForever actionWithAction:animate]; 
     repeat = [CCRepeat actionWithAction:animate times:1]; 
     [self runAction:repeat]; // this is will work fine 
    } 
    return self; 
} 

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event 
{ 
    [self runAction:repeat]; // This is where the app crashes 
    state = kBodyPartTouched; 
    return YES; 
} 

回答

1

您需要保留它們並在dealloc中釋放它們。考慮使用屬性。