How to drag a sprite in cocos2d-x | Techbirds
bool HelloWorld::isTouchingSprite(CCTouch* touch) { if(tag==1) return (ccpDistance(ball->getPosition(), this->touchToPoint(touch)) < 100.0f); } CCPoint HelloWorld::touchToPoint(CCTouch* touch) { // convert the touch object to a position in our cocos2d space return CCDirector::sharedDirector()->convertToGL(touch->getLocationInView()); } void HelloWorld::ccTouchesBegan(CCSet* touches, CCEvent* event) { this->touchOffset = CCPointZero; CCTouch* touch = (CCTouch*)(touches->anyObject()); CCPoint location = touch->getLocationInView(); location = CCDirector::sharedDirector()->convertToGL(location); if(ball->boundingBox().containsPoint(location)&&ball->getTag()==1) { tag=1; if(