0

我正在尝试从 applicationDidEnterBackground: 方法显示暂停游戏层,并且由于某种原因它确实调用了该方法,但没有任何反应。

代表


- (void)applicationDidEnterBackground:(UIApplication*)application {
        ship = [[Ship alloc] init];
        [ship pause];

暂停方法


- (void)pause
{


    BOOL isPaused = [[CCDirector sharedDirector] isPaused];

    if(!isPaused) 
    {
        //Pause the game
        ccColor4B c = {100,100,0,100}; 
        PauseLayer *pauseLayer = [[[PauseLayer alloc] initWithColor:c] autorelease]; 

        [self.leftMenuItem setIsEnabled:NO];
        [self.rightMenuItem setIsEnabled:NO];
        [self.fireMenuItem setIsEnabled:NO];

        [self addChild:pauseLayer z:10 tag:100];
        [[CCDirector sharedDirector] pause];        
    }
}

暂停层


+ (id)scene
{
    CCScene *scene = [CCScene node];
    PauseLayer *layer = [PauseLayer node];
    [scene addChild:layer];
    return scene;
}


- (id)initWithColor:(ccColor4B)color
{
    if((self = [super initWithColor:color])) 
    {
        self.isTouchEnabled = YES; 
        [CCMenuItemFont setFontName:@"Marker Felt"];
        [CCMenuItemFont setFontSize:40];

        CCMenuItemFont *resumeGameItem = [CCMenuItemFont itemFromString:@"Resume" target:self selector:@selector(resumeGame)];
        CCMenuItemFont *menuGameItem = [CCMenuItemFont itemFromString:@"Menu" target:self selector:@selector(goToGameMenu)];

        CCMenu *menu = [CCMenu menuWithItems:resumeGameItem,menuGameItem,nil];
        [menu alignItemsVerticallyWithPadding:40.00];

        [self addChild:menu];
    }
    return self;
}

谢谢!

4

1 回答 1

1

如果您在委托中初始化船,它不会添加到我可以看到的任何 cocos 层中。您必须获取对当前场景的引用并将船添加到其中(假设船是 Cocos 节点的子类)。

于 2011-03-28T18:56:02.253 回答