Cocos2d显示层问题

时间:2011-03-28 18:46:45

标签: cocos2d-iphone layer cclayer

我正在尝试从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];        
    }
}

PauseLayer


+ (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;
}

谢谢!

1 个答案:

答案 0 :(得分:1)

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