How to Display Image in SKShapeNodeby
I have been using SKShapeNode extensively to draw quick graphics by filling them with CGPaths for quick visual debugging and making prototypes. For example I can create procedural mountains quickly with SKShapeNode. In early times of spritekit SKShapeNode didn’t have way to render images on it. We have fillTexture available now that allows texture to fill the shape.
let shapeNode = SKShapeNode() shapeNode.fillTexture = SKTexture(imageNamed: “testImage")
But, Our SKShapeNode is displaying nothing.
Why is that?
Let’s see what documentation says:
fillColor of SKShapeNode is .clear which blends with our provided image texture. To make our texture visible without any blending we use .white
let shapeNode = SKShapeNode() shapeNode.fillColor = .white shapeNode.fillTexture = SKTexture(imageNamed: “testImage")
You might also like: Blurry Pixel Font in SpriteKit bug
You might also like: AVAudioPlayer not playing any sound
You might also like: App crashing when saving photos from WKWebView