有没有一种方法可以绘制带有纹理的圆形SKSpriteNode?或者,用纹理绘制SKShapeNode的方法呢?
需要考虑的是所有的图片都是矩形/正方形。我们所看到的圆形,实际上只是显示彩色像素的方法:圆形外部是透明的,内部是彩色的部分。
we add the sprite to the scene
let shape: SKShapeNode = SKShapeNode(circleOfRadius: 50)
shape.name = "shape"
shape.lineWidth = 1 // this way we see that this is a circle
shape.fillColor = .white // to see the true colors of our image
//shape.strokeColor = .white
//shape.glowWidth = 0
shape.fillTexture = SKTexture(imageNamed:"myImage")
shape.position = CGPoint(x: 0, y:200)
self.addChild(shape)
let newTexture: SKTexture = (self.view?.texture(from: self.childNode(withName: "shape")!))!
let sprite: SKSpriteNode = SKSpriteNode(texture: newTexture)
self.addChild(sprite)
shape.removeFromParent()
view?.texture(from: shape)
来创建一个纹理,而不必将其添加到场景中。 - 0x141E