Swift SpriteKit makes physics from image texture slow down my application too slowly

I am trying to make an iOS application that includes collision detection between two physical bodies. I want one of the physical bodies to be the form of the image that I use, but when I try to do this using the texture, it slows down my application a lot and ultimately causes it to completely freeze. These are two lines of code causing this:

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

however, if I changed these two lines to something like

 physicsBody = SKPhysicsBody(rectangleOfSize: size) 

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

+5
source share
1 answer

This may be due to the complex nature of your texture, but it's hard to say without seeing it. As Whirlwind said, this probably should not lead to such a significant slowdown, but it is difficult to solve without additional information.

To get around creating SKPhysicsBody from a texture, you need to use an online tool to create a body from a path. I use this tool personally. It can be a decent job.

+5
source

All Articles