码迷,mamicode.com
首页 > 其他好文 > 详细

Cocos2d-x -- 图片菜单按钮

时间:2015-08-27 12:37:16      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

Scene* MainMenu::createScene()
{
    // ‘scene‘ is an autorelease object
    auto scene = Scene::create();
    
    // ‘layer‘ is an autorelease object
    auto layer = MainMenu::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool MainMenu::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();
    
    auto menuTitle = MenuItemImage::create("MainMenuScreen/Game_Title.png",
                                           "MainMenuScreen/Game_Title.png");
    auto playItem = MenuItemImage::create("MainMenuScreen/Play_Button.png",
                                          "MainMenuScreen/Play_Button(Click).png",
                                          CC_CALLBACK_1(MainMenu::GoToGameScene, this));
    
    auto menu = Menu::create(menuTitle, playItem, NULL);
    menu->alignItemsVerticallyWithPadding(visibleSize.height / 4);
    this->addChild(menu);
    
    return true;
}

void MainMenu::GoToGameScene(cocos2d::Ref *pSender)
{
    auto scene = GameScreen::createScene();
    
    Director::getInstance()->replaceScene(scene);
}

 

Cocos2d-x -- 图片菜单按钮

标签:

原文地址:http://www.cnblogs.com/davidgu/p/4762633.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!