Skip to content

Instantly share code, notes, and snippets.

@levinotik
Created March 15, 2012 17:40
Show Gist options
  • Save levinotik/2045541 to your computer and use it in GitHub Desktop.
Save levinotik/2045541 to your computer and use it in GitHub Desktop.
CGPoint touchLocation = CCDirector.sharedDirector().convertToGL(CGPoint.make(ev.getX(), ev.getY()));
if(touchLocation.x > largestX || touchLocation.x < smallestX) {
if(!(touchLocation.y > largestY || touchLocation.y < smallestY)) {
sprite.setPosition(sprite.getPosition().x, touchLocation.y);
}
} else if(touchLocation.y > largestY || touchLocation.y < smallestY) {
if(!(touchLocation.x > largestX || touchLocation.x < smallestX)) {
sprite.setPosition(touchLocation.x, sprite.getPosition().y);
}
} else {
sprite.setPosition(touchLocation.x, touchLocation.y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment