你好,我正在爲我的cocos2d遊戲製作一個暫停屏幕。我有3個按鈕:恢復按鈕,重試按鈕和選項按鈕。他們都沒有迴應觸摸和做他們應該做的事情。當暫停屏幕拉起時,我的所有動作都暫停使用此代碼:cocos2d暫停屏幕中的按鈕不起作用
[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");
}
你好@ K1laba現在的問題是我的暫停菜單中的按鈕沒有響應觸摸。 – PoKoBros