I'm having some problem with the runAction method for CCAnimation. If I run the command after I've created the CCAnimate within the initWithBodyPartImage it will work fine with no errors. But, If I call the runAction method with in the ccTouchBegan function the app will crash and no error is printed out to the console. So It's really hard to figure out why the app is crashing when I call the runAction method from a different function. If anyone can help me with this I'd much appreciated it?
-(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;
}
You need to retain them and release them in dealloc. Consider using properties.
精彩评论