2

I'm using an SKTexture with an image and set the SKPhysicsBody. Like that:

var moleTexture = SKTexture(imageNamed: "moleTop1")

leftPlayer = SKSpriteNode(texture: moleTexture)
leftPlayer.physicsBody = SKPhysicsBody(texture: moleTexture, size: leftPlayer.texture!.size())

Now after I start my game, I noticed that the physicsBody is set wrong. I've activated the showPhysics property and my image looks like that:

enter image description here

As you see, the only thing which is used by SKPhysicsBody is the little part on the middle left(blue border).

How can I change that so that the whole image will be used?

Christian
  • 22,585
  • 9
  • 80
  • 106
  • 1
    That looks interesting. I believe it will only create an outline (or one shape) and it appears to be starting from the left and because there are no other pixels near enough it calls it done. I wonder if you get a different result of those pixels are touching. I would try and validate that first. If that is the case you may have to change the texture or use a different variation of the texture. – Skyler Lauren Mar 08 '15 at 21:05
  • @SkylerLauren You are absolutely right. That did the trick. Please write that as an answer. I want to give you an upvote :) – Christian Mar 08 '15 at 21:17
  • Glad that helped. I have wondered before how it would handle textures with transparency like you have...now we know =) – Skyler Lauren Mar 08 '15 at 21:22

1 Answers1

2

That looks interesting. I believe it will only create an outline (or one shape) and it appears to be starting from the left and because there are no other pixels near enough it calls it done.

I wonder if you get a different result if those pixels are touching. I would try and validate that first. If that is the case you may have to change the texture or use a different variation of the texture for the physical body.

I hope that helps =)

Skyler Lauren
  • 3,792
  • 3
  • 18
  • 30