5

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];
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
  • 1
    Please write down your solution in a separate answer and mark it as the accepted answer. That way it is easier for other people to find. – CloakedEddy May 30 '14 at 15:30

2 Answers2

7

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];
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
2

You should try with snapshotViewAfterScreenUpdates: method from UIView.

Your SKScene is inside an SKView that has this method.

After that you can extract the image from the view, and create a SKNode with it.

gabuh
  • 1,166
  • 8
  • 15