2010-09-26 36 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中释放它们。考虑使用属性。