5

I'm trying to make an iOS app that includes some collision detection between two physics bodies. I want one of the physics bodies to be the shape of an image I am using, but when I try to do this using a texture it slows my app down tremendously and eventually causes it to freeze altogether. These are the two lines of code that are causing it:

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

however, if I change these two lines to something like

physicsBody = SKPhysicsBody(rectangleOfSize: size)  

then everything runs perfectly fine. Has anyone else had this problem and/or found a solution?

Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136
Jason Cook
  • 51
  • 1
  • 2
  • Does this happen while bodies moving, or when collide, or... ? I just tested this and I can't produce what you are saying. Creating physics body from texture is expensive but it should not be that much to slow down your app just because of one physics body. ? Try to use empty project and go step by step. First make a physics body from texture and check does that slows down an app. If not, go further and move body by applying an impulse to it. If everything works, try to make a collision. etc. That way you will be sure what makes a problem, because what you are doing should work. Good luck! – Whirlwind May 12 '15 at 10:07
  • I also faced same problem when i added about 10 spikes with triangle shape to my scene. – Jaffer Sheriff May 13 '15 at 09:40

1 Answers1

5

This may be due to the complex nature of your texture, but it's hard to tell without seeing it. As Whirlwind said, it probably shouldn't cause such a significant slowdown however it's difficult resolve without further information.

A way to get around creating the SKPhysicsBody from a texture would be to use an online tool for building the body from a path. I use this tool personally. It may be a decent work around.

Mason
  • 271
  • 2
  • 12