【发布时间】:2012-08-03 14:58:43
【问题描述】:
我在使用 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;
}
【问题讨论】:
标签: iphone