如何将背景图像设置为spritenode的边界?

时间:2015-02-17 12:20:46

标签: ios swift sprite-kit

想要将图像作为边界添加到spriteNode物理体,图像可能会动态变化,图像应该是spritenode的边界。

1 个答案:

答案 0 :(得分:0)

您可以从纹理创建physicsBody,并在更改图像时重新指定body

目标C:

SKTexture *texture = [SKTexture textureWithImageNamed:@"imageFileName"];
myNode.physicsBody = [SKPhysicsBody bodyWithTexture:texture size:texture.size];

夫特:

let texture = SKTexture(imageNamed: "imageFileName");
myNode.physicsBody = SKPhysicsBody(texture: texture, size: texture.size());