我在使用CCAnimation的runAction方法时遇到了一些问题。如果我在initWithBodyPartImage中创建CCAnimate之后运行命令,它将正常工作,没有错误。但是,如果我在ccTouchBegan函数中调用runAction方法,应用程序将崩溃并且没有错误打印到控制台。因此,当我从另一个函数调用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;
}
答案 0 :(得分:1)
你需要保留它们并在dealloc中释放它们。考虑使用属性。