SKShapeNode filltexture () does not display image

I want to create a circle whose content is an image (.png), and based on the SKShapeNode class reference, I thought I could use the SKShapeNode.filltexture () function to set the texture on the image. But when I run the code below, I get a circle, but the "cat-black" image that I am trying to load is not displayed. I checked that my Image.Assets has an image with the correct name, so there is something else. Any ideas? I added the following result:

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 } 

enter image description here

+5
source share
1 answer

The documentation states

The default value is nil. If a fill texture is specified, the fillColor property is ignored, and the filled part of the node form is rendered using the texture instead [selection added].

This suggests that the form must be filled in or the texture will not be visible; so if you set the fill color of the form with

 circle.fillColor = .white 

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

 circle.fillColor = .blue 
+11
source

Source: https://habr.com/ru/post/1239235/


All Articles