Skip to content

Instantly share code, notes, and snippets.

@indatawetrust
Last active May 18, 2016 20:50
Show Gist options
  • Save indatawetrust/0f0fa8e505b8f54b5c2d3a4152a0bfd9 to your computer and use it in GitHub Desktop.
Save indatawetrust/0f0fa8e505b8f54b5c2d3a4152a0bfd9 to your computer and use it in GitHub Desktop.
cocos2d-x sprite touch event run action
auto sprite = Sprite::create("HelloWorld.png");
auto listener1 = EventListenerTouchOneByOne::create();
listener1->onTouchBegan = [](Touch* touch, Event* event){
auto sprite = event->getCurrentTarget();
Point pt = touch->getLocation();
Rect recTemp= sprite->boundingBox();
if(recTemp.containsPoint(pt)) {
auto scaleTo = ScaleTo::create(2,2);
sprite->runAction(scaleTo);
}
return false;
};
listener1->onTouchMoved = [](Touch* touch, Event* event){
};
listener1->onTouchEnded = [=](Touch* touch, Event* event){
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, sprite);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment