COCOS2D-X 3.0初體驗

首先是類的變化,類開頭都去掉了“CC”,如 CCMenu 變成了 Menu,但前提得引用 using namespace cocos2d;
菜單的使用
//3.0版本
    MenuItemFont *menuItem = MenuItemFont::create("start game", CC_CALLBACK_1(HomeMenuLayer::OnStartGame, this));
void HomeMenuLayer::OnStartGame(Object *sender)
{
    Director::getInstance()->end();    //個人對“getInstance”還是比較中意的,可以對比下2.0的版本。
}

//2.0版本
    CCMenuItemFont *menu_item = CCMenuItemFont::create("Start Game", this, menu_selector(HomeMenuLayer::OnStartGame));
void HomeMenuLayer::OnStartGame(CCObject *sender)
{
    CCDirector::sharedDirector()->end();
}

觸摸事件則需用事件進行註冊
單點觸摸事件註冊
    auto listener1 = EventListenerTouchOneByOne::create();
    //若設為 true ,則觸摸事件會被吞噬,不會再向下傳遞
    listener1->setSwallowTouches(false);
    listener1->onTouchBegan = CC_CALLBACK_2(WelcomeLayer::onTouchBegan, this);
    listener1->onTouchMoved = CC_CALLBACK_2(WelcomeLayer::onTouchMoved, this);
    listener1->onTouchEnded = CC_CALLBACK_2(WelcomeLayer::onTouchEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, this);


多點事件註冊
    

    auto listener1 = EventListenerTouchOneByOne::create()
    ...
    ...
    listener1->onTouchesMoved = CC_CALLBACK_2(WelcomeLayer::onTouchesMoved, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, this);
不再需要 setTouchEnable(true);

你可能感兴趣的:(linux,3.0,menu,cocos2d-x,CCMenu)