cocos2dx 自定义事件

前端之家收集整理的这篇文章主要介绍了cocos2dx 自定义事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

创建自定义事件:

Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    auto listener = EventListenerCustom::create("MyEvent",[](EventCustom *event){
        CCLOG("Hello %s",(char*)event->getUserData());
    });

    Director::getInstance()->getEventDispatcher() ->addEventListenerWithFixedPriority(listener,1);

触发事件:

EventCustom e("MyEvent");
    e.setUserData((void*)("Lidaha"));

    Director::getInstance()->getEventDispatcher()->dispatchEvent(&e);

猜你在找的Cocos2d-x相关文章