美文网首页
Cocos2d-x学习笔记1:场景切换

Cocos2d-x学习笔记1:场景切换

作者: 丿沧海一粟丿 | 来源:发表于2017-07-04 16:54 被阅读0次
    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();
    }
    

    相关文章

      网友评论

          本文标题:Cocos2d-x学习笔记1:场景切换

          本文链接:https://www.haomeiwen.com/subject/gjsxhxtx.html