5

So, basically, I have a sprite (.png) in SpriteKit, where most of the pixels are zero/no detail etc.

I wish to create a UIBezierPath of only the detail inside the Sprite, so later I can use containsPoint.

After a bunch of googling I found you can create a PhysicsBody using the path of the Texture in the sprite image, like this:

    let texture = SKTexture(imageNamed: "myImage.png")
    img.physicsBody = SKPhysicsBody(texture: texture, size: img.size)

This creates a physics body around only the detail inside the image, excluding any alpha value pixels, if you know what I mean.

Is there a way to create a BezierPath doing the same? or maybe creating a CGPath, then using that to create a BezierPath?

The reason is, I'm hoping to test if a CGPoint is inside this sprite, without using the physicsDelegate or physicsBodys.

Thanks in advance.

Reanimation
  • 3,151
  • 10
  • 50
  • 88
  • Maybe you can pull the `img.physicsBody` path after creating the physics body? I'm not sure that that will be a `BezierPath` though. – Gliderman Mar 19 '16 at 21:37
  • 2
    I thought that, because you can create a bezier from a CGPath but I'm not sure how to access the physics body path... So without some complex algorithm I don't think it's achievable easily – Reanimation Mar 20 '16 at 18:30
  • sorry to be a bother to you. Did you ever find a way to pull out the CGPath from a PhysicsBody? – Confused Oct 21 '16 at 02:06
  • No I didn't :( unfortunately. – Reanimation Oct 21 '16 at 10:22

0 Answers0