How to detect a touch on rotated CCSprite?
I'm familiar with the general technique using CCTTouchbaggan and content size, anchorpoint etc. can detect Sprite that one touch was within its range ... but I'm not sure that once the angel Has been rotated by an angle
I want the SPREAT to detect the touch (encapsulation) and report the incident to another object by a representative.
If someone has some code to share ... it would be nice.
Try using CCND Convert TouchTone Nodespaceer: The method to change the point in rotated coordinates And then you can compare the extent of the phantom.
I have made it a category on CCNode, so it is available for any CCNode or subclass.
@interface CCNode (gndUtils) // See a node test to see if there is a touch. // Parents keep in mind the scaling / rotation / change of all the parents in the series. // Note that rotation of a rectangle does not produce a rectangle // (and we are using a simple rectangle test) // so it is testing the smallest rectangle attached to the curved node. // converstion to see it and then the coordinates of the world / / If you are testing a lot of nodes, then manually convert converstion / // CGPoint = [see in touch location: [touch view]]; // Convert "View" // Touch = [[CCCCitre Shared Director] ConvertTOGL: Touch Lock]; // Go to "World" // and then use WorldPoint in node: for efficiency rather than method - (BOOL) touch in node: (UIT * touch); // allows a node to check if there is a world point in it - (BOOL) worldPointInNode: (CGPoint) worldpoint; @end More implementation:
@implementation CCNode (gndUtils) - (BOOL) TouchInnode: (UITT *) touch {CGPoint touchLoc = [touch location Iniview: [touch view]]; // Convert "window" to "View coordinate" Probably touch == [[CCCCitre Share Director] ConvertToGL: Touch Lock]; // Transfer to "Cocos 2D World Coordinate" [Self-WorldPointInon: Tchlok]; } (BOOL) worldPointInNode: (CP point) WorldPoint {// level node considers the boundary of the world to be coordinated so that we can see if the world is in the node node. CGRect bbox = CGRectMake (0.0f, 0.0f, self content size.width, self.contentSize.height); // Find the bounding box in the local box = CGRectApplyAffineTransform (bbox, [self-nodeToWorldTransform]); // Change the box to world coordinate, scaling, etc. CGRectContainsPoint (Beebox, WorldPoint); } @end
Comments
Post a Comment