Created
January 24, 2014 03:41
-
-
Save ryohey/8591683 to your computer and use it in GitHub Desktop.
create Touch Event Listener and set up callback methods in cocos2d-x v3.0beta0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // in a layer initialize method such as the onEnter | |
| auto listener = cocos2d::EventListenerTouchOneByOne::create(); | |
| listener->onTouchBegan = [](Touch *, Event *) { | |
| // do something | |
| return true; | |
| }; | |
| listener->onTouchMoved = [](Touch* touch, Event* event) { | |
| // do something | |
| }; | |
| listener->onTouchEnded = [this](Touch* touch, Event* event) { | |
| // do something like | |
| float touchX = touch->getLocation().x; | |
| CCLog("%f", touchX); | |
| }; | |
| listener->onTouchCancelled = [](Touch* touch, Event* event) { | |
| // do something | |
| }; | |
| getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment