Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将背景图像设置为spritenode的边界?_Ios_Swift_Sprite Kit - Fatal编程技术网

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

Ios 如何将背景图像设置为spritenode的边界?,ios,swift,sprite-kit,Ios,Swift,Sprite Kit,要将图像作为边界添加到spriteNode物理实体,图像可能会动态更改,图像应该是spriteNode的边界。您可以从纹理创建physicsBody,并在每次更改图像时重新指定实体 目标C: SKTexture *texture = [SKTexture textureWithImageNamed:@"imageFileName"]; myNode.physicsBody = [SKPhysicsBody bodyWithTexture:texture size:texture.size];

要将图像作为边界添加到spriteNode物理实体,图像可能会动态更改,图像应该是spriteNode的边界。

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

目标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());

我想设置一个图像作为物理体的边界,这样物理体就不会移出边界(图像)。