2

I am creating a game and I need to draw some obstacles on in (SKNodes), depending on the level (background image). Let's say I have a tree, i would like to draw borders around it as in the picture below:

enter image description here

I will need the coordinates to create a physicsBody.

Is there a simple way to do it? (maybe a software?)

I will need to adapt the same coordinates for different devices, therefore I believe it's too complicated to manually do it.

Any ideas?

Thanks!

MeV
  • 3,761
  • 11
  • 45
  • 78

2 Answers2

2

There is a SKPhysicsBody class method that could be of help:

+ bodyWithTexture:size:

From the description:

Use this method when your sprite has a shape that you want replicated in its physics body. The texture is scaled to the new size and then analyzed. A new physics body is created that includes all of the texels in the texture that have a nonzero alpha value. The shape of this body attempts to strike a good balance between performance and accuracy. For example, fine details may be ignored if keeping them would cause a significant performance penalty.

ZeMoon
  • 20,054
  • 5
  • 57
  • 98
  • 1
    So this could potentially work with png transparent images. It's quite interesting. Great! Thank you! – MeV May 07 '15 at 10:41
1

Check out this SKPhysicsBody Path Generator.

You can easily create a path as you desire with this tool (but make sure you read the rules at the top right)

giorashc
  • 13,691
  • 3
  • 35
  • 71