1

I'm trying to determine if a point is inside a node that's been rotated. I've tried the following code in my scene:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */
    UITouch *touch = [touches anyObject];
    if ([self.cardNode containsPoint:[touch locationInNode:self.cardNode.parent]]) {
        NSLog(@"HIT");
    }
}

But it seems that the nodes frame is still the same as to when it's not rotated. In other words, points outside of the rotated node (which are in the node when it's not rotated) are considered to be inside of it. I've also tried using CGRectContainsPoint which produced the same results.

How can I determine if a point is in a rotated node?

Manool
  • 11
  • 1
  • 1

1 Answers1

0

In case if you have two textures you can use .contactTestBitMask property for two physical bodies so if they overlapping you will get notification and you can do whatever you want, that is it! (notice that you don't have to make any collision just notification) Here you should read about physicsBody property and didBeginContact method.

Because physics bodies created by texture so if they rotating it means that it's texture rotating so you will get what do you want.

But in case if you want to check if you touch is in location of some node, so you can use property

yourTouch.locationInNode(SOME_NODE)

Hope it helps!

wm.p1us
  • 2,019
  • 2
  • 27
  • 38
  • Hi, sorry I don't quite understand. Could you provide me with an example? Here is a picture of what is happening: http://imgur.com/Ixzw0bk The white box is a rotated SKSpriteNode. The red dot is where I am touching, which is resulting in the code in my original post to print "HIT". Thanks – Manool Oct 16 '15 at 03:22