Handling of touch events in cocos2d-x3.2
First usage, first we need to be in. H file defines a touch callback, where we first get the 3 states of the single touch
1:bool Ontouchbegan (Touch * touch,event *unused_event);//Start State
2:void ontouchmoved (Touch *touch,event *unused_event);//Move State
3:void ontouchended (touch*touch,event *unused_event);//End State
And then we go. The init () inside of CPP defines our touch monitoring
Auto Listener=eventlistenertouchonebyone::create ();
Listener->ontouchbegan=cc_callback_2 (Gamescene::ontouchbegan,this);
Listener->ontouchmoved=cc_callback_2 (Gamescene::ontouchmoved,this);
Listener->ontouchended=cc_callback_2 (Gamescene::ontouchended,this);
Director::getinstance ()->geteventdispatcher ()->addeventlistenerwithscenegraphpriority (listener,this);
Then we implement the 3 callback methods defined in. h
void Gamescene::ontouchbegan (Touch * touch,event *unused_event)
{
Log ("Implement Touch Start")
}
void Gamescene::ontouchmoved (Touch*touch,event*unused_event)
{
Log ("Implement touch move to process event")
}
void gamescene::ontouchended (Touch *touch,event*unused_event)
{
Log ("Operation after touch completion")
}
That's the first way, and then we'll be able to do a 2nd of the simpler
We're directly in. CPP inside direct write touch event written in Init () method inside
Auto Listener=eventlistenertouchonebyone::create ();
Listener->ontouchbegan=[&] (Touch *touch,event*event)->bool{
Log ("Here you can write the event you need to touch")
}
Listener->ontouchended=[&] (Touch *touch,event*event)
{
Log ("Touch Move")
}
Listener->ontouchended=[&] (Touch *touch,event*event) {
Log ("Touch End")
}
Load Touch
This->geteventdispatcher ()->addeventlistenerwithscenegraphpriority (listener,this);
cocos2d-x3.2 a summary of touch events