SKShapeNode filltexture() does not display image

我们两清 提交于 2019-12-22 05:27:01

问题


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

}


回答1:


The documentation states

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

the texture will appear. You can also set fillColor with a different color to colorize the texture:

circle.fillColor = .blue


来源:https://stackoverflow.com/questions/34468567/skshapenode-filltexture-does-not-display-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!