-
MoseHasLikes 0Problem Description
Hi there. I have just finished a class for pop-out menu. Unfortunately, it would not work properly.Would you mind checking it for me? Thanks.
I have debugged for 1 hour and could not figure out.
#include "PauseMenuScene.h" #include "Definitions.h" #include "MenuPrimeScene.h" bool PauseMenuScene::init() { if(!Scene::init()) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); auto bgSprite = Sprite::create("bg_mainscene.jpg"); bgSprite->setPosition(visibleSize.width / 2, visibleSize.height / 2); this->addChild(bgSprite,-1); auto pauseLabel = Label::createWithTTF("PAUSE", FONT_PATH, visibleSize.width*FONT_SIZE); pauseLabel->setPosition(visibleSize.width / 2, visibleSize.height * 0.8); this->addChild(pauseLabel); auto menuButton = MenuItemImage::create("MainMenuButton.png", "MainMenuButtonClicked.png", CC_CALLBACK_1(PauseMenuScene::returnScene, this)); menuButton->setPosition(visibleSize.width / 2, visibleSize.height / 2); this->addChild(menuButton); return true; } void PauseMenuScene::returnScene(Ref* pSender) { log("push MenuPrimeScene"); auto scene = MenuPrimeScene::create(); Director::getInstance()->pushScene(scene); }
The problem is pretty strange. As you can see, I create a button for returning to the main menu and display a different picture when I click.
MainMenuButton.png (with shadow effect)
MainMenuButtonClicked.png (without shadow effect)
And I use log to see if I successfully run returnScene(), and yet it did not work. It showed no message.
It seems that the game was halted at PauseMenuScene.
Why? Cannot figure out.
-
MoseHasLikes 0
Problem fixed. I am an idiot.
I should create a menu to put the menu buttons in and addChild(menu) instead of addChild(menuButton)
Login to reply