0

I'm trying to include a pause feature for my game. So far running pause on the [CCDirector sharedDirector] has been good enough when run through my pauseGame method (which incorporates a BOOL to tell if game is paused, etc.)

However, I noticed that if I go back to the homescreen on my device, my application delegate will automatically run pause and resume on the sharedDirector.

Ideally, I would like access my active scene/layer's so I can run my own pause method.

How can I: 1) check if the current scene is my game scene 2) access the game scene's pause property, and run the pauseGame method on it?

Any help appreciated. Thanks

4

2 回答 2

0

我使用不同的方法来暂停游戏。

我通常有一个带有游戏层的游戏场景。为了暂停游戏,我添加了一个新层(覆盖整个屏幕),当我暂停游戏时,我会显示这个层。这样,您可以停止触摸游戏层的事件并在恢复游戏时恢复它们(并从场景中删除暂停层)

于 2012-06-12T08:44:31.583 回答
0

跑步场景是[CCDirector sharedDirector].runningScene

如果你调用 [场景 pauseSchedulerAndActions]; 在当前场景中,在主屏幕来回切换时不会恢复。

如果您需要暂停层次结构中的所有节点,这里是扩展 CCNode 的方法

-(void)recursivePauseSchedulerAndActions {
    [self pauseSchedulerAndActions];
    CCNode *child;
    CCARRAY_FOREACH(children_, child) {
        [child recursivePauseSchedulerAndActions];
    }
}
-(void)recursiveResumeSchedulerAndActions {
    [self resumeSchedulerAndActions];
    CCNode *child;
    CCARRAY_FOREACH(children_, child) {
        [child recursiveResumeSchedulerAndActions];
    }
}
于 2012-06-11T18:33:26.033 回答