swiftcolorssprite-kitskshapenode

How do I remove color from node in spritekit


I have tile nodes with textures on, and if you press a tile it's highlighted with an SKColor. Now, if I press the tile again, I would like for the color to vanish, only showing the texture underneath. I know about .clear but this makes the whole tile transparent, removing the texture as well in the process. Just wondering if there is a way to remove the color I just added so that I can see the texture again.


Solution

  • From Apple's documentation on SKShapeNode.fillTexture:

    Important

    The default fill color of a SKShapeNode is SKColor.clear. Since the fill texture is blended with the fill color, fillColor needs to be set to a non-clear color for it to display. For example, to display the texture without any color blend effects, set fillColor to SKColor.white.

    So based on this it seems you could solve by setting the color to white.