Cocosd-x3.1 Menu使用樣本

來源:互聯網
上載者:User

標籤:blog   http   color   os   io   使用   ar   for   檔案   

1、標頭檔

#include "cocos2d.h"USING_NS_CC;class MenuItemDemo : public cocos2d::Layer{public:    // there's no 'id' in cpp, so we recommend returning the class instance pointer    static cocos2d::Scene* createScene();        // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone    virtual bool init();        // a selector callback    void menuCloseCallback(cocos2d::Ref* pSender);        // implement the "static create()" method manually    CREATE_FUNC(MenuItemDemo);};

2、cpp檔案

#include "MenuItemDemo.h"USING_NS_CC;Scene* MenuItemDemo::createScene(){    // 'scene' is an autorelease object    auto scene = Scene::create();        // 'layer' is an autorelease object    auto layer = MenuItemDemo::create();        // add layer as a child to scene    scene->addChild(layer);        // return the scene    return scene;    }bool MenuItemDemo::init(){    bool bRet = false;    do{        CC_BREAK_IF(!Layer::init());        auto winSize = Director::getInstance()->getWinSize();        //文字功能表項目        auto item1 = MenuItemFont::create("Item Font Test",[&](Ref* sender)                                          {                                              log("Item Font CallBack called");                                          });        item1->setFontSize(40);        item1->setFontName("Marker Felt");        item1->setPosition(Vec2(winSize.width/4,winSize.height/3*2));                auto menu1 = Menu::create(item1,NULL);        menu1->setPosition(Vec2::ZERO);        addChild(menu1);                //圖片功能表項目        auto item2 = MenuItemImage::create("CloseNormal.png","CloseSelected.png",[&](Ref* sender){            log("MenuItemImage");        });        item2->setPosition(Vec2(winSize.width/2,winSize.height/3*2));        menu1->addChild(item2);        //標籤功能表項目        auto item3 = MenuItemLabel::create(LabelTTF::create("Label Test", "Arial", 40), [&](Ref* sender){            log("Label CallBack called");        });        item3->setPosition(Vec2(winSize.width/4*3,winSize.height/3*2));        menu1->addChild(item3);        //觸發器功能表項目,實現開關關閉效果        auto item4 = MenuItemToggle::createWithCallback([&](Ref* sender){            log("Toggle Touched");        }, MenuItemFont::create("On"),MenuItemFont::create("Off"),NULL);        MenuItemFont::setFontName("Marker Felt");        MenuItemFont::setFontSize(35);        item4->setPosition(Vec2(winSize.width/4,winSize.height/3));        menu1->addChild(item4);        //高亮效果        auto item5 = MenuItemFont::create("Notice This Menu",[&](Ref* sender){            log("MenuItem touched");        });        item5->setPosition(Vec2(winSize.width/2,winSize.height/3));        auto color_action = TintBy::create(0.5f, 0, -255, -255);        auto color_back = color_action->reverse();        auto seq = Sequence::create(color_action,color_back, NULL);        item5->runAction(RepeatForever::create(seq));        menu1->addChild(item5);        //移動菜單        auto item6 = MenuItemFont::create("Move MenuItem",[&](Ref*){            log("Move Item Called");        });        item6->setPosition(Vec2(winSize.width/4*3,winSize.height/3));        auto moveTo = MoveTo::create(2.25, Vec2(winSize.width/4*3,winSize.height-30));        item6->runAction(moveTo);        menu1->addChild(item6);                                        bRet = true;    }while (0);        return bRet;}

3、


Cocosd-x3.1 Menu使用樣本

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.