themaxgoldman
themaxgoldman

Reputation: 123

SpriteKit PhysicsBody: Could not create physics body for basic shape

I have an extremely basic polygon that is the texture for a sprite in my game, yet when I try and create a physicsBody from this texture for the sprite I get this error:

2016-06-19 08:25:21.707 Space Escape[14677:5651144] PhysicsBody: Could not create physics body.

Also, the game uses many different simple polygons and for some the physicsBody can be created, yet for others it gets an error.

func setPhysics(size: CGSize) {

    self.physicsBody = SKPhysicsBody(texture: asteroidTexture, size: size)
    self.physicsBody?.angularDamping = 0
    self.physicsBody?.angularVelocity = 2

}

Here is the texture:

Simple Heptagon Sprite Texture

Upvotes: 6

Views: 1739

Answers (2)

Alessandro Ornano
Alessandro Ornano

Reputation: 35412

I've experimented that this kind of physical representation could be decelerate your collisions. Instead of it, if you don't require extreme precision to the physical bodies of your sprites try to use:

self.physicsBody = SKPhysicsBody(circleOfRadius: size.width/2)

It is much lighter and slimmer for the cpu calculations. You can see the big difference when your game is almost completed (for example 80%). I hope this helps.

Upvotes: 0

Luca Angeletti
Luca Angeletti

Reputation: 59536

In my playground it is working. Try replacing the size parameter as in the code below and let me know

let asteroidTexture = SKTexture(imageNamed: "sprite")
let physicsBody = SKPhysicsBody(texture: asteroidTexture, size: asteroidTexture.size())

Upvotes: 1

Related Questions