0

I remember since the origins of SpriteKit that it has never supported a SKCropNode inside another SKCropNode. For that reason I decided to use a SKEffectNode along with the shouldRasterize property in the child node, which seems to work fine.... until now.

Since iOS 9.2 the sprites inside the SKEffectNode using this property now are either not showing or showing a plain white texture. As SKCropNode inside SKCropNode still doesn't work I'm out of options.

Does anyone know a workaround for this? Or should I just file a radar to Apple?

gzafra
  • 496
  • 3
  • 10

1 Answers1

0

We found another "hackish" workaround for this problem. Basically, instead of using a SKEffectNode to rasterize it you can use - (nullable SKTexture *)textureFromNode:(SKNode *)node from SKView.

So, previously it was sort of:

SKEffectNode *rasterizedSprite = [SKEffectNode node];
SKSpriteNode *mask = [SKSpriteNode spriteNodeWithImageNamed:@"maskImage"];
SKCropNode *cropNode = [SKCropNode node];
[cropNode setMaskNode: mask];
[cropNode addChild: spriteToMask];

[rasterizedSprite addChild:cropNode];
rasterizedSprite.shouldRasterize = YES;

[self addChild:rasterizedSprite];

Now it's like:

SKSpriteNode *mask = [SKSpriteNode spriteNodeWithImageNamed:@"maskSprite"];

SKCropNode *cropNode = [SKCropNode node];
[cropNode setMaskNode: mask];
[cropNode addChild: spriteToMask];

SKView *view = [[SKView alloc]init];

SKSpriteNode *rasterizedSprite = [SKSpriteNode spriteNodeWithTexture:[view textureFromNode:cropNode]];

[self addChild:rasterizedSprite];

This workaround might give problems with iOS8 and below...

gzafra
  • 496
  • 3
  • 10