Answer the question
In order to leave comments, you need to log in
cocos2d-x menu not working?
Good afternoon!
I'm learning cocos2d-x and ran into a problem: the menu does not work.
#include "MenuScene.h"
#include "GameScene.h"
#include "ui/CocosGUI.h"
#include <iostream>
USING_NS_CC;
Scene* MenuScene::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
auto layer = MenuScene::create();
scene->addChild(layer);
return scene;
}
void MenuScene::GoToGameScene(cocos2d::Ref* sender) {
auto director = Director::getInstance();
auto scene = GameScene::createScene();
director->replaceScene(TransitionFade::create(0.5,scene));
}
bool MenuScene::init()
{
if (!Layer::init())
{
return false;
}
auto visibleSize = Director::getInstance()->getVisibleSize();
auto origin = Director::getInstance()->getVisibleOrigin();
auto playButton = MenuItemImage::create("CloseNormal.png", "CloseNormal.png",CC_CALLBACK_1(
MenuScene::GoToGameScene,this));
playButton->setScale(1.0f);
playButton->setEnabled(true);
playButton->setPosition(visibleSize.width/2+origin.x, visibleSize.height / 2 + origin.y);
auto menu = Menu::create(playButton, NULL);
menu->setPosition(Point::ZERO);
this->addChild(menu);
return true;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question