6

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

  • I had similar issue for for my sprites. When I changed Texture images from sprite sheet images to image-set images for SKPhysicsBody, this error went away. – ZippyMind Dec 02 '16 at 08:17

2 Answers2

1

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())
Luca Angeletti
  • 58,465
  • 13
  • 121
  • 148
  • Changed it to `self.physicsBody = SKPhysicsBody(texture: asteroidTexture, size: asteroidTexture.size())` but I still get the same error. – themaxgoldman Jun 19 '16 at 13:19
  • @user1947112 Ok, then it could be related to the image. If the transparent part has some pixel it can create problems. Could you regenerate your image from zero? – Luca Angeletti Jun 19 '16 at 13:20
  • I have, it was created in Adobe Illustrator as a simple polygon with a transparent background, the image was attached above, I'm sure there's no extra pixels. It's very strange that some of the images created the exact same way do work. – themaxgoldman Jun 19 '16 at 14:08
  • @user1947112: yes it's strange. I'm still trying to find the reason – Luca Angeletti Jun 19 '16 at 14:10
  • @appzYourLife could you please check out my post, been at it for a while https://stackoverflow.com/questions/44294768/how-to-rotate-sprites-around-a-joint – Containment Jun 05 '17 at 08:49
0

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.

Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133