0

I'm new use Cocos2d. I have a problem show in picture link(sorry I could upload picture directly). how I can check red sprite position inside the black region?
http://postimg.org/image/86f6ol2mh/

Liya
  • 99
  • 6
  • oh, that's really easy .... http://stackoverflow.com/questions/217578/point-in-polygon-aka-hit-test/218081#218081 – CodeSmile Jun 14 '14 at 06:23

1 Answers1

1

You can use LearnCocos2D sugestion or if you don't need exactly this shape maybe you can get by with radius from center of image.

- (BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint location = [touch locationInView:[touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];
    location = [self convertToNodeSpace:location];

    float dist = pow(YOURSPRITE.position.x - location.x, 2) + pow(YOURSPRITE.position.y - location.y, 2);
    dist = sqrt(dist);

    if (dist <= 70) { //use some value for radius (70)

    }
}
denis alenti
  • 78
  • 1
  • 6