Created
September 17, 2012 07:11
-
-
Save denniss/3735987 to your computer and use it in GitHub Desktop.
dragging object in Cocos2d
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
//Capture touch only when the touch lies within _draggableObject | |
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { | |
CGPoint currentLocation = [self convertTouchToNodeSpace:touch]; | |
return CGRectContainsPoint(_draggableObject.boundingBox, currentLocation); | |
} | |
//Updates the _draggableObject position as touch moves | |
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event{ | |
CGPoint location = [touch locationInView:[touch view]]; | |
CGPoint convertedLocation = [[CCDirector sharedDirector] convertToGL:location]; | |
_draggableObject.position = CGPointMake(convertedLocation.x, _draggableObject.position.y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment