cocos2d::ui::Button
Instead of cocos2d::MenuItemSprite , you can use cocos2d::ui::Button when you need to specify an action/event other than the button press released.
#include "cocosGUI.h" USING_NS_CC; auto size= Director::getInstance()->getVisibleSize(); auto button= ui::Button::create("normal.png", "selected.png", "", ui::Widget::TextureResType::PLIST); button->setPosition(size/2); this->addChild(button); button->addTouchEventListener([](Ref* sender, ui::Widget::TouchEventType type) { switch (type) { ui::Widget::TouchEventType::BEGAN: CCLOG("touch began"); break; ui::Widget::TouchEventType::MOVED: CCLOG("touch moved"); break; ui::Widget::TouchEventType::ENDED: CCLOG("touch ended"); break; default: break; } });
If the you want to use cached sprite frames, you have to specify the 4th argument as cocos2d::ui::Widget::TextureResType::PLIST .
The default value is cocos2d::ui::Widget::TextureResType::LOCAL .