Cocos2d iphone Cocos2d-动作和动画不会暂停
当我这样做时:Cocos2d iphone Cocos2d-动作和动画不会暂停,cocos2d-iphone,ccaction,Cocos2d Iphone,Ccaction,当我这样做时: [gameLayer pauseSchedulerAndActions]; 大多数游戏都会暂停,但正在进行此操作的精灵不会暂停旋转: [sprite runAction:[CCRepeatForever actionWithAction:[CCRotateBy actionWithDuration:5.0 angle: 360]]]; 此外,运行cAnimations的精灵不会停止设置动画: CCAnimation *theAnim = [CCAnimation animat
[gameLayer pauseSchedulerAndActions];
大多数游戏都会暂停,但正在进行此操作的精灵不会暂停旋转:
[sprite runAction:[CCRepeatForever actionWithAction:[CCRotateBy actionWithDuration:5.0 angle: 360]]];
此外,运行cAnimations的精灵不会停止设置动画:
CCAnimation *theAnim = [CCAnimation animationWithSpriteFrames:theFrames delay:0.1];
CCSprite *theOverlay = [CCSprite spriteWithSpriteFrameName:@"whatever.png"];
self.theAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:theAnim]];
游戏暂停时,我如何让这些暂停?我希望“pauseSchedulerAndActions”暂停操作,但事实似乎并非如此代码>应暂停所有动画和动作。尝试
[[CCDirector sharedDirector]暂停]代码>它应该暂停所有动画和动作。暂停日程安排动作不是递归的,因此它只会影响正在暂停的节点上的动作和日程安排,而不会影响其子节点
如果您的场景/层很浅,您可能只需在层的子层中循环并在每个子层上调用(暂停/恢复)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
}
}
}
因此,在您的情况下,您可以尝试调用此方法并传入您的gameLayerpauseSchedulerAndActions不是递归的,因此它只会影响正在暂停的节点上的操作和计划,而不会影响其子节点
如果您的场景/层很浅,您可能只需在层的子层中循环并在每个子层上调用(暂停/恢复)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
}
}
}
因此,在您的情况下,您可以尝试调用此方法并传入您的游戏玩家您是否尝试过[[CCDirector sharedDirector]pause]?您是否尝试过[[CCDirector sharedDirector]pause]?是的,这很有效。不错。这样做而不是[[CCDirector sharedDirector]pause]有什么好处吗?如果暂停该控制器,它会暂停所有内容,但可能会出现这样的情况:当另一层暂停时,您希望在另一层中运行动作或动画。例如,可以暂停游戏层,但在HUD层中继续设置分数标签的动画。是的,这很有效。不错。这样做而不是[[CCDirector sharedDirector]pause]有什么好处吗?如果暂停该控制器,它会暂停所有内容,但可能会出现这样的情况:当另一层暂停时,您希望在另一层中运行动作或动画。例如,可以暂停游戏层,但在HUD层中继续设置分数标签的动画。