Search code examples
iossprite-kitsktextureskeffectnode

Render SKScene to SKTexture?


Is there a way in Sprite Kit that I can capture the screen (all the current SKScene rendered nodes) to an SKTexture so that I can apply a CIFilter and then assign the SKTexture back to a new SKSpriteNode?

I know that I can set an SKEffectNode, as the parent of my node tree, apply a filter etc and get the result that way but I really need to have a filtered SKTexture (or SKSpriteNode) that I can reuse later?

EDIT:

Possible solution:

textureFromNode:
Renders and returns a Sprite Kit texture that contains the node’s contents.

Yup that works:

   SKTexture *texture = [[self view] textureFromNode:[self scene]];
   [blurSprite setTexture:texture];

Solution

  • From Apple docs:

    textureFromNode: Renders and returns a Sprite Kit texture that contains the node’s contents.

    Code example:

       SKTexture *texture = [[self view] textureFromNode:[self scene]];
       [blurSprite setTexture:texture];