Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 541
Jason Cook Avatar asked May 11 '15 04:05

Jason Cook


1 Answers

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.

like image 107
Mason Avatar answered Oct 29 '22 16:10

Mason