【发布时间】:2012-11-27 14:47:34
【问题描述】:
我想在游戏中的松鼠英雄触摸水果时为其设置动画。动画后必须将水果从场景中移除。我已经尝试了 2 周,但没有做对。我的精灵表有6 帧用于精灵动画。
目前,当英雄与水果相交时,我正在执行以下代码:
NSMutableArray *burst = [NSMutableArray array];
for(int i = 1; i <= 6; ++i) {
[burst addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Fruit01000%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation animationWithFrames:burst delay:0.02f];
CCActionInterval *animAction = [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO];
[expl stopAllActions];
expl.visible = TRUE;
expl.position = ccp(coinColl.position.x,coinColl.position.y);
cleanupAction = [CCCallFuncND actionWithTarget:self selector:@selector(explOver:) data:expl];
seqF = [CCSequence actions:animAction, cleanupAction, nil];
[expl runAction:seqF];
[platformLayer removeChild:coinColl cleanup:YES];
[self sumScore];
[coinLabel setString: [NSString stringWithFormat:@"%i",appDelegate.coinScore+appDelegate.levelScore]];
explOver() 函数:
-(void) explOver:(CCSprite*)explosion{
explosion.visible = FALSE;
}
它的工作部分,一些水果不显示动画,跳转到下一个场景时应用程序崩溃,给出错误“指针被释放未分配”
【问题讨论】:
-
看this awesome code,看看猴子碰到香蕉时的动画逻辑。 :)
-
我没有使用任何物理编辑器。
-
您实际上有什么问题?您无法检测到松鼠与水果的碰撞,或者您不知道动画完成后如何移除精灵?
-
碰撞效果很好,动画和移除是问题。
-
@SpencerWong 它是从 tilemap 检索到的水果位置。
标签: iphone animation cocos2d-iphone sprite