在cocos2d菜单中暂停图层时没有响应?

时间:2011-06-25 21:29:51

标签: iphone objective-c cocos2d-iphone

我试图创建一个游戏画面。它会创建一个新图层并将其放在当前游戏图层的顶部,并有一个菜单可以让你回家。但是,在我暂停所有操作后,菜单没有响应,这有什么办法吗?谢谢!

 //Pause all actions
    [[CCDirector sharedDirector] pause];

    //Create new black layer
    CCLayerColor *gameover = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 75)];
    [self addChild:gameover z:1];

    //add menu
    CCMenuItemFont *item1 = [CCMenuItemFont itemFromString:@"Continue" target:self selector:@selector(goToMainMenu)];
    CCMenu *menu = [CCMenu menuWithItems:item1, nil];
    [gameover addChild:menu z:110];

编辑:我正在尝试在顶部创建一个透明层

5 个答案:

答案 0 :(得分:2)

暂停共享导演暂停所有内容......我昨天刚问过这个问题:

Is there anyway to have a the menu work even when I pause the game?

你可以做那个人所做的事情以及我发现的另一种方法,它只会使你所有的预定选择器失效(即[self unschedule:@selector(gameLogicLoop:)];

然后,您可以在完成单击菜单([self schedule:@selector(gameLogicLoop:)];)后重新安排这些内容。

答案 1 :(得分:1)

我把所有内容都包装在一个BOOL中,它对我来说很好。

BOOL paused;

-(void)goToMainMenu
{
    if (paused == YES)
    {
         [[CCDirector sharedDirector] replaceScene:[MainMenu scene]];
    }
}

-(void)gameOver
{
    paused = YES;
    [[CCDirector sharedDirector] pause]];
}

-(id) init
{
    if((self=[super init]))
    {
       paused = NO;
       [self gameOver];
    }
    return self;
}

编辑:

为什么要将CCMenu添加到CCLayerColor?只需将其添加到CCLayer即可。

[self addChild:menu];

希望这有帮助!

答案 2 :(得分:1)

-(void)MenuStatus:(BOOL)_enable Node:(id)_node
{
    for (id result in ((CCNode *)_node).children) {
        if ([result isKindOfClass:[CCMenu class]]) {
            for (id result1 in ((CCMenu *)result).children) {
                if ([result1 isKindOfClass:[CCMenuItem class]]) {
                    ((CCMenuItem *)result1).isEnabled = _enable;
                }
            }
        }
        else
            [self MenuStatus:_enable Node:result];
    }
}

然后像

一样打电话
[self MenuStatus:YES Node:self]; //YES to Enable or NO to Disable the layer specified

答案 3 :(得分:0)

  CCSprite *background = [CCSprite spriteWithFile:@"background3.png"];
    //[background initWithFile:@"background3.png"];
    [background setPosition:ccp(screenSize.width/2, screenSize.height/2)];
    [self addChild:background z:1];
    [background setOpacity:420];

要使其成为FadeIn,这应该有效:

 CCLayerColor _shadowLayer = [CCLayerColor layerWithColor: ccc4(0,0,0, 0)];
[_shadowLayer setContentSize: CGSizeMake(_winSize.width, _winSize.height)];

_shadowLayer.anchorPoint = ccp(0.0f, 0.0f); 
_shadowLayer.position = ccp(0, 0);

[self addChild: _shadowLayer];

[_shadowLayer runAction: [CCFadeTo actionWithDuration:1.5f opacity:100]];

答案 4 :(得分:0)

您还可以通过以下方法获得所需内容

-(void) pause:(ccTime)dt
{
    NSLog(@"Pausing");
    CCDirector *director = [CCDirector sharedDirector];
    self.pausedTargets = [director.actionManager pauseAllRunningActions];
}

-(void) resume:(ccTime)dt
{
    NSLog(@"Resuming");
    CCDirector *director = [CCDirector sharedDirector];
    [director.actionManager resumeTargets:self.pausedTargets];
}