HelloWorldScene.cpp
void HelloWorld::menuCloseCallback(Ref* pSender)
{
//Close the cocos2d-x game scene and quit the application
// Director::getInstance()->replaceScene(SecondScene::createScene());
//加动画
// Director::getInstance()->replaceScene(
// TransitionSlideInT::create(3.0f, SecondScene::createScene())
//
// );
//push过去
Director::getInstance() -> pushScene(SecondScene::createScene());
}
ScondScene
bool SecondScene::init() {
Label *label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
label -> setPosition(Vec2(300, 100));
this -> addChild(label);
/*添加按钮*/
MenuItemImage *pCloseItem = MenuItemImage::create("CloseNormal.png", "CloseSelected.png", this, menu_selector(SecondScene::popScene));
pCloseItem->setPosition(Vec2(Director::getInstance() -> getWinSize().width - 20, 20));
pCloseItem -> setPosition(Vec2(100, 100));
Menu *pMenu = Menu::create(pCloseItem, NULL);
this -> addChild(pMenu);
return true;
}
//一定要在h文件中声明
void SecondScene::popScene(Ref *pSender) {
Director::getInstance() -> popScene();
}
网友评论