SKPhysicsBody仅使用SKTexture的一部分

时间:2015-03-08 19:42:43

标签: swift sprite-kit skphysicsbody sktexture

我正在使用带有图像的SKTexture并设置SKPhysicsBody。像那样:

var moleTexture = SKTexture(imageNamed: "moleTop1")

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

现在,在我开始游戏之后,我注意到physicsBody设置错误。我已激活showPhysics属性,我的图片看起来像这样:

enter image description here

如您所见,SKPhysicsBody使用的唯一内容是左中间的小部分(蓝色边框)。

如何更改它以便使用整个图像?

1 个答案:

答案 0 :(得分:2)

看起来很有趣。我相信它只会创建一个轮廓(或一个形状),它似乎是从左边开始,因为没有其他像素足够接近,所以它称之为完成。

我想知道如果那些像素在触摸,你会得到不同的结果。我会首先尝试验证。如果是这种情况,您可能需要更改纹理或为物理体使用不同的纹理变体。

我希望帮助=)