0

I am trying to detect a touch on a CCSprite using:

@implementation MainScene{
    CCPhysicsNode *_levelView;
}

- (void)touchBegan:(CCTouch *)touch withEvent:(CCTouchEvent *)event{
    CGPoint location = touch.locationInWorld;
    CCSprite *clickedSprite;

    for (CCSprite *obj in _levelView.children)
    {
        if (CGRectContainsPoint(obj.boundingBox, location))
            clickedSprite = obj;
    }
}

which works perfectly fine. So I can detect clicked Sprites already. Since I am using sprites which are transparent at some parts, they are also detected when the transparent part of the sprite is clicked.

But I want to exclude the transparent part from the detection…

For the physics I am using physics shape polygon. Is there a way to use this polygon for something like:

polygonContainsPoint(obj.physicsPolygon, location)

? Or maybe even a way saying all pixels but those with transparency 100? Or an even easier solution?

cocoseis
  • 1,443
  • 1
  • 13
  • 35
  • Why can't you use the location of the touch? See [this question](http://stackoverflow.com/questions/4704538/detecting-if-a-specific-sprite-was-touched-on-cocos2d-iphone). – Droppy Jun 03 '15 at 13:36
  • I can detect clicked Sprites already. But they are also detected when the transparent part of the sprite is clicked. I want to exclude the transparent part from the detection… – cocoseis Jun 03 '15 at 13:38
  • OK that makes it clearer. – Droppy Jun 03 '15 at 13:43
  • You're going to need to use the normal "find node under finger" approach and then manually reject the selection based on your criteria (not sure how to do that). Of course if you reject the selection you will want to "find the next node under finger". It's a pretty complicated problem. – Droppy Jun 04 '15 at 09:09
  • Is there any way to get the area of the physics polygon? – cocoseis Jun 04 '15 at 09:10

0 Answers0