c++ - menu callback in not called -
i want add couple of buttons - "settings" , "restart" scene, placed above everything. below [in init()]:
auto settingsmenu = menuitemimage::create("settings_gold@2x.png", "settings_white@2x.png", cc_callback_1(gamelevellayer::settingsbuttontapped, this)); settingsmenu->setposition(point(440, 280)); this->addchild(settingsmenu);
i add touch handler process game "actions," below:
// handle user touches auto dispatcher = director::getinstance()->geteventdispatcher(); auto listener = eventlistenertouchonebyone::create(); listener->ontouchbegan = cc_callback_2(gamelevellayer::ontouchbegan, this); listener->ontouchended = cc_callback_2(gamelevellayer::ontouchended, this); dispatcher->addeventlistenerwithscenegraphpriority(listener, this);
my ontouchbegan() , ontouchended() called fine, settingsbuttontapped() never called, touch handler apparently swallows everything.
how should processed in cocos2d-x 3.x, clicking on menu calls settingsbuttontapped()?
thank you
a colleague advised cocos2d-x 3.x way use ui:button, instead of menuitemimage.
changed code be:
auto settingsbutton = cocos2d::ui::button::create(); settingsbutton->settouchenabled(true); settingsbutton->loadtextures("settings_gold@2x.png", "settings_white@2x.png"); settingsbutton->setposition(point(440, 270)); settingsbutton->addtoucheventlistener(cc_callback_2(gamelevellayer::settingsbuttontapped, this)); this->addchild(settingsbutton); // handle user touches auto dispatcher = director::getinstance()->geteventdispatcher(); auto listener = eventlistenertouchonebyone::create(); listener->ontouchbegan = cc_callback_2(gamelevellayer::ontouchbegan, this); listener->ontouchended = cc_callback_2(gamelevellayer::ontouchended, this); dispatcher->addeventlistenerwithscenegraphpriority(listener, this);
now, pressing button calls button callback, , touches on layer still processed were.
Comments
Post a Comment