Jason Cook
Jason Cook

Reputation: 51

Swift SpriteKit making physicsbody from texture of an image slows down my app too much

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?

Upvotes: 5

Views: 2701

Answers (1)

Mason
Mason

Reputation: 271

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.

Upvotes: 5

Related Questions