您好,我正在为我的 cocos2d 游戏制作暂停屏幕。我有 3 个按钮:恢复按钮、重试按钮和选项按钮。他们都没有对触摸做出反应并做他们应该做的事情。当暂停屏幕被拉起时,我的所有操作都使用以下代码暂停:
[self pauseSchedulerAndActions];
[[CCDirector sharedDirector]pause];
[[CCDirector sharedDirector] replaceScene:[CCTransitionScene transitionWithDuration:1.0 scene:[PauseMenu scene]]];
这是我的暂停菜单的代码。我想知道为什么暂停屏幕中的按钮对触摸没有响应,以及恢复按钮和重试按钮代码在我想做的事情中是否正确。对于恢复按钮,我只希望暂停菜单层消失,然后 CCActions 需要恢复。对于我的重试按钮,我只想通过调用启动游戏的 GameScene 层来重新启动游戏。这是代码:
-(id)init{
if((self = [super init])){
CGSize size = [[CCDirector sharedDirector]winSize];
screenWidth = size.width;
screenHeight = size.height;
resumeButton = @"resume.png";
retryButton = @"retry.png";
optionsButton = @"optionspause.png";
pausedLabel = [CCSprite spriteWithFile:@"paused.png"];
pausedLabel.position = ccp(screenWidth/2, screenHeight/1.5);
[self addChild:pausedLabel z:0];
[self makeTheMenu];
}
return self;
}
-(void)makeTheMenu{
CCMenuItem* theResumeButton;
CCMenuItem* theRetryButton;
CCMenuItem* theOptionsButton;
theResumeButton = [CCMenuItemImage itemWithNormalImage:resumeButton selectedImage:resumeButton target:self selector:@selector(resumeTheGame)];
theResumeButton.scale = 2;
theRetryButton = [CCMenuItemImage itemWithNormalImage:retryButton selectedImage:retryButton target:self selector:@selector(retryTheGame)];
theRetryButton.scale = 2;
theOptionsButton = [CCMenuItemImage itemWithNormalImage:optionsButton selectedImage:optionsButton target:self selector:@selector(optionsMenu)];
theOptionsButton.scale = 2;
thePauseMenu = [CCMenu menuWithItems:theResumeButton, theRetryButton, theOptionsButton, nil];
thePauseMenu.position = ccp(screenWidth/2, screenHeight/2 - 100);
[thePauseMenu alignItemsHorizontallyWithPadding:20];
[self addChild:thePauseMenu z:1];
}
-(void)resumeTheGame{
[self resumeSchedulerAndActions];
[[CCDirector sharedDirector]resume];
[thePauseMenu removeFromParentAndCleanup:YES];
}
-(void)retryTheGame{
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[GameScene scene] withColor:ccBLACK]];
}
-(void)optionsMenu{
CCLOG(@"options");
}