0

I have a SKSpriteNode which has a PNG texture, partly transparent.

I want to make a logical split line on this sprite and then measure the volume or opaque pixel count in each part. The object of the exercise is to tell what percentage total sprite volume exists in each part.

I have done some research and came empty. Seems there are no built in methods to do so. Can you guide me in the right direction here?

Kashif
  • 4,642
  • 7
  • 44
  • 97
  • One way might be creating a "getPixel" and iterate the subareas and count / check your condition. This would be really inefficient but it might to be a start. You could progress from there. https://stackoverflow.com/q/25146557/1804251 – bemeyer Aug 22 '17 at 19:37

1 Answers1

1

you could create a "pixel perfect" SKPhysicsBody like this:

let sprite = SKSpriteNode(imageNamed: "Spaceship")
sprite.physicsBody = SKPhysicsBody(texture: sprite.texture!,
                                   size: sprite.texture!.size())

And then access the property sprite.physicsBody.area which gives you the area of the body in square meters (you can convert it to points, here is the documentation)

Stoneburner
  • 220
  • 1
  • 8