0
我試圖顯示來自applicationDidEnterBackground暫停遊戲層:方法,由於某種原因它調用該方法,但沒有任何反應。的Cocos2D顯示層問題
代表
- (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;
}
謝謝!
你好,謝謝你的回答,我所有的類從CCLayer繼承,它仍然調用該方法,但什麼也沒有發生 – jkigel 2011-03-28 19:38:50
如何船被添加到科科斯層?我沒有在上面的代碼中看到它。 AppDelegate不是一個cocos節點。必須將船舶添加到圖層才能顯示。 – TigerCoding 2011-03-28 19:46:32
使用CCDirector獲取當前場景並將其添加到它。 – TigerCoding 2011-03-28 20:06:13