cocos2d-x3.2 a summary of touch events

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.