当我这样做时:
[gameLayer pauseSchedulerAndActions];
大多数游戏暂停,但正在进行此操作的精灵不会暂停旋转:
[sprite runAction:[CCRepeatForever actionWithAction:[CCRotateBy actionWithDuration:5.0 angle: 360]]];
此外,那些运行CCAnimations的精灵不会停止动画:
CCAnimation *theAnim = [CCAnimation animationWithSpriteFrames:theFrames delay:0.1];
CCSprite *theOverlay = [CCSprite spriteWithSpriteFrameName:@"whatever.png"];
self.theAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:theAnim]];
暂停游戏时如何暂停这些操作?我希望“pauseSchedulerAndActions”可以暂停操作,但情况似乎并非如此。
答案 0 :(得分:4)
pauseSchedulerAndActions不是递归的,因此它只会影响您正在暂停的节点上的操作和计划,而不是它的子节点。
如果您的场景/图层很浅,您可能只是通过图层的子项循环并在每个子图上调用(暂停/恢复)SchedulerAndActions,否则,如果您有更深的图形,您可能想要调用它是递归的。我写了一个小测试,这对我有用:
-(void) pauseSchedulerAndActions: (BOOL) pause forNodeTree:(id)parentNode shouldIncludeParentNode:(BOOL)includeParent
{
if(includeParent)
{
(pause) ? [parentNode pauseSchedulerAndActions] : [parentNode resumeSchedulerAndActions];
}
for( CCNode *cnode in [parentNode children] )
{
(pause) ? [cnode pauseSchedulerAndActions] : [cnode resumeSchedulerAndActions];
if(cnode.children.count > 0)
{
[self pauseSchedulerAndActions:pause forNodeTree:cnode shouldIncludeParentNode:NO]; // on recurse, don't process parent again
}
}
}
所以在你的情况下你可以尝试调用这个方法并传入你的gameLayer
答案 1 :(得分:2)
尝试[[CCDirector sharedDirector] pause];
它应暂停所有动画和动作。