Created
November 10, 2013 16:55
-
-
Save zaneclaes/7400737 to your computer and use it in GitHub Desktop.
Detecting hit areas on a cocos2d sprite
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
@implementation MySprite | |
// The internal rect representing the current texture | |
- (CGRect)hitArea { | |
CGPoint bl = CGPointMake(MIN(_quad.tl.vertices.x, _quad.bl.vertices.x), MIN(_quad.bl.vertices.y, _quad.br.vertices.y)); | |
CGPoint tr = CGPointMake(MAX(_quad.tr.vertices.x, _quad.br.vertices.x), MAX(_quad.tl.vertices.y, _quad.tr.vertices.y)); | |
return CGRectMake(bl.x, bl.y, tr.x - bl.x, tr.y - bl.y); | |
} | |
// Works just like .boundingBox (eg, represents the hitArea in parent coordinates) | |
- (CGRect)hitBox { | |
return CGRectApplyAffineTransform(self.textureArea, [self nodeToParentTransform]); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment