SKShapeNode filltexture()不显示图像 [英] SKShapeNode filltexture() does not display image
问题描述
我想创建一个内容为图像(.png)的圆,并基于SKShapeNode类引用,我认为可以使用SKShapeNode.filltexture()函数将纹理设置为图像.但是,当我运行下面的代码时,我得到了圆圈,但是我尝试加载的猫黑"的图像没有显示.我检查了我的Image.Assets是否具有正确名称的图像,因此出现了其他情况. 有任何想法吗?我在下面附加了输出:
I want to create a circle that whose content is an image (.png), and based on the SKShapeNode class reference, I thought that I could use SKShapeNode.filltexture() function to set the texture to the image. But when i run the code below, I get the circle, but the image of the "cat-black" I am trying to load doesn't show. I checked that my Image.Assets have the image with the correct name, so something else is up. Any ideas? I attached the output below:
func newCircle(photo:String, position:CGPoint) -> SKShapeNode {
let circle = SKShapeNode.init(circleOfRadius: 27)
circle.fillTexture = SKTexture.init(image: UIImage(named: "cat-black")!)
circle.strokeColor = UIColor.greenColor()
circle.lineWidth = 4
circle.name = "aggroNode"
circle.position = position
return circle
}
推荐答案
文档说明
默认值为nil.如果指定了填充纹理,则fillColor属性将被忽略,并且填充部分 形状节点是使用纹理而不是[强调添加]渲染的.
The default value is nil. If a fill texture is specified, the fillColor property is ignored and the filled portion of the shape node is rendered using the texture instead [emphasis added].
这表明必须填充形状,否则纹理将不可见;因此,如果您将形状的填充颜色设置为
This suggests that the shape must be filled or the texture will not be visible; therefore, if you set the shape's fill color with
circle.fillColor = .white
纹理将会出现.您还可以将fillColor
设置为其他颜色以使纹理着色:
the texture will appear. You can also set fillColor
with a different color to colorize the texture:
circle.fillColor = .blue
这篇关于SKShapeNode filltexture()不显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!