I'm trying to do a basic radar, where I have a sprite that is triangular shaped. I want it to rotate from the top point, so I set the anchor point to (0.5,1). Everything seems to work by now.
Now I need this to detect collisions, so I added a physicsBody to this sprite, and here comes my problem. PhysicsBody won't rotate around the same point as the sprite does due to the anchor point.
Here's a piece of code from my radar:
radar = [SKSpriteNode spriteNodeWithImageNamed:@"radar.png"];
/* Triangular path */
CGFloat offsetX = radar.frame.size.width * radar.anchorPoint.x;
CGFloat offsetY = radar.frame.size.height * radar.anchorPoint.y;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 1 - offsetX, 1 - offsetY);
CGPathAddLineToPoint(path, NULL, 175 - offsetX, 1 - offsetY);
CGPathAddLineToPoint(path, NULL, 91 - offsetX, 239 - offsetY);
CGPathCloseSubpath(path);
/*end path*/
radar.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path];
radar.physicsBody.dynamic = NO;
radar.anchorPoint = CGPointMake(0.5, 1);
radar.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
And here's an image where you can see what happens. (PhysicsBody -> Green, RadarSprite->Blue, Point where I want it to rotate around->Red dot, Angle of rotation->Red arrows)
So, the question is, what can I do to fix this? Thank you very much in advance