有没有办法绘制带有纹理的圆形SKSpriteNode?或者,绘制一个带有纹理的 SKShapeNode?p>
最佳答案
考虑到所有图像都是矩形/正方形。我们所看到的圆形,就是我们如何显示彩色像素:圆外面的东西是透明的,而里面的东西是彩色部分。
- 我们需要一个圆
- 我们对其进行纹理处理
- 我们将其添加到场景中
- 我们从刚刚添加到场景中的形状节点取回新纹理
- 我们使用这个新纹理制作一个新的 Sprite
我们将 Sprite 添加到场景
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()
关于swift - 画一个带有纹理的圆形SKSpriteNode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45783547/