我使用了 Hailei 的代码,但创建了一个适合我的类别。
CCNode+additions.h
#import "CCNode.h"
@interface CCNode (additions)
-(void)pauseSchedulerAndActionsRecursive;
-(void)resumeSchedulerAndActionsRecursive;
@end
CCNode+additions.m
#import "CCNode+additions.h"
@implementation CCNode (additions)
-(void)pauseSchedulerAndActionsRecursive {
[self pauseSchedulerAndActions];
for (CCNode *child in [self children]) {
[child pauseSchedulerAndActionsRecursive];
}
}
-(void)resumeSchedulerAndActionsRecursive {
[self resumeSchedulerAndActions];
for (CCNode *child in [self children]) {
[child resumeSchedulerAndActionsRecursive];
}
}
@end
因此,暂停时,请先在游戏节点上调用 pauseSchedulerAndActionsRecursive,然后再将“暂停菜单节点”添加到游戏节点(否则暂停节点也会暂停,因此无法使用)。