Created
October 5, 2014 12:40
-
-
Save tid-kijyun/3509dd3c774b16c015a6 to your computer and use it in GitHub Desktop.
cocos2d-x 3.x : setup touch event
This file contains 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
bool HelloWorld::init() | |
{ | |
// ... | |
auto listener = EventListenerTouchOneByOne::create(); | |
listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this); | |
listener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchMoved, this); | |
listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this); | |
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this); | |
// ... | |
} | |
bool HelloWorld::onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *unused_event) | |
{ | |
Director *pDirector = Director::getInstance(); | |
Point touchPoint = pDirector->convertToGL(touch->getLocationInView()); | |
return true; | |
} | |
void HelloWorld::onTouchMoved(cocos2d::Touch *touch, cocos2d::Event *unused_event) | |
{ | |
} | |
void HelloWorld::onTouchEnded(cocos2d::Touch *touch, cocos2d::Event *unused_event) | |
{ | |
} |
This file contains 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
class HelloWorld : public cocos2d::Layer | |
{ | |
// ... | |
virtual bool onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *unused_event); | |
virtual void onTouchMoved(cocos2d::Touch *touch, cocos2d::Event *unused_event); | |
virtual void onTouchEnded(cocos2d::Touch *touch, cocos2d::Event *unused_event); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment