SKEffectionNodes
have a shouldRasterise "switch" that bakes them into a bitmap, and doesn't update them until such time as the underlying nodes that are impacted by the effect are changed.
However I can't find a way to create an SKTexture
from this rasterised "image".
Is it possible to get a SKTexture
from a SKEffectNode
?
I've figured this out, in a way that solves my problems, using a Factory.
Read more on how to make a factory, from BenMobile's patient and clear articulation, here: Factory creation and use for making Sprites and Shapes
There's an issue with blurring a
SKTexture
orSKSpriteNode
in that it's going to run out of space. The blur/glow goes beyond the edges of the sprite. To solve this, in the below, you'll see I've created a "framer" object. This is simply an emptySKSpriteNode
that's double the size of the texture to be blurred. The texture to be blurred is added as a child, to this "framer" object.It works, regardless of how hacky this is ;)
Inside a static factory class file:
Inside anywhere you can access the Sprite you want to make a shadow or glow texture for:
-
button
is a texture of the button to be given a shadow.a:
is an alpha setting (actually transparency level, 0.0 to 1.0, where 1.0 is fully opaque) the lower this is the lighter the shadow will be.The positioning serves to drop the shadow slightly below the button so it looks like light is coming from the top, casting shadows down and onto the background.
I think you could try a code like this (it's just an example):
Update:
After you answer, hope I understood better what do you want to achieve.
This is my point of view: if you want to make a shadow of a texture, you could simply create an
SKSpriteNode
with this texture:What I want to say is that you could proceed step by step:
This way of working produces a series of useful methods you could use in your project to build other kind of elements. Maybe, by separating the tasks you don't need to use
texture(from:)