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?

4

1 回答 1

0

我们为这个问题找到了另一种“hackish”解决方法。SKEffectNode基本上,您可以使用- (nullable SKTexture *)textureFromNode:(SKNode *)nodefrom来代替使用 a来栅格化它SKView

所以,以前是这样的:

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];

现在是这样的:

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];

此解决方法可能会给 iOS8 及以下版本带来问题...

于 2015-12-15T17:38:19.950 回答