Click the drag button, want to let the layer monitor hear the screen touch event, you can drag the button to start setting settouchenabled to false;
Cases:
#include "Ui/uibutton.h"
BOOL Mydemo::init () {
Set Up Click events
Eventlistenertouchonebyone *listener = Eventlistenertouchonebyone::create ();
Listener->ontouchbegan = Cc_callback_2 (Mydemo::ontouchbegan, this);
listener->ontouchmoved = Cc_callback_2 (mydemo::ontouchmoved, this);
listener->ontouchended = Cc_callback_2 (mydemo::ontouchended, this);
Binding
Geteventdispatcher ()->addeventlistenerwithscenegraphpriority (listener, this);
Button creation
Button *BTN = * * *;
BTN->addtoucheventlistener (Cc_callback_2 (Mydemo::btncallback, this));
This->addchild (BTN);
}
void Mydemo::btncallback (Ref *p, Cocos2d::ui::widget::toucheventtype type) {
Button *BTN = (button *) p; //
if (type = = Widget::toucheventtype::began) {
Btn->setposition (VEC2 (Btn->getpositionx ()-btn->getpositiony () + 15));
Btn->settouchenabled (FALSE);
}
}
BOOL Mydemo::ontouchbegan (Cocos2d::touch *touch, cocos2d::event *event) {
return true;
}
void Mydemo::ontouchmoved (Cocos2d::touch *touch, cocos2d::event *event) {
Cclog ("-------------------%d--------------", a++);
}
void mydemo::ontouchended (Cocos2d::touch *touch, cocos2d::event *event) {
}
When you drag a button, you enter the Ontouchmoved method
Cocos2d-x: Solve the problem of touching the touch event on the layer where you clicked the drag button