Search code examples
swiftsprite-kittexturesstrokeskshapenode

SpriteKit. Why .strokeTexture does not work for SKShapeNode?


I can't understand why the "strokeTexture" option isn't working on a SKShapeNode. Or, how can I do border with texture? Thanks in advance!

let shape = SKShapeNode(circleOfRadius: 100)
shape.position = CGPoint(x: 200, y: 400)
shape.fillColor = SKColor.white
shape.fillTexture = SKTexture(imageNamed: "test")
shape.lineWidth = 50
shape.strokeColor = SKColor.white
shape.strokeTexture = SKTexture(imageNamed: "test(5)")

Output:

enter image description here

Test image: enter image description here

Test(5) image: enter image description here


Solution

  • It doesn't work in Simulator!

    Try it on your device.

    I get the feeling this stroke might be being done with metal, whereas the fill is somehow not being done with metal, so is visible in the simulator.

    The fill also doesn't rotate with the object on the device, but the stroke/outline and its texture do.

    This would tend to indicate that an SKShapeNode without a fill might have reasonable performance.