7

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

}

enter image description here

malena
  • 798
  • 11
  • 26

1 Answers1

18

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
0x141E
  • 12,613
  • 2
  • 41
  • 54
  • Thank you so much, that was the issue.! – malena Dec 26 '15 at 15:57
  • I've done all this, but can't use one texture from an SKTextureAtlas, instead the entire textureAtlas is being shown inside the circle. Do you know anything about this? – Confused Oct 07 '16 at 22:46