我试图在游戏中为节点添加磨砂玻璃效果。例如http://bit.ly/1vNMvAG 这样做的正确方法是什么?
答案 0 :(得分:1)
我必须遗漏一些东西,因为我会留在SpriteKit,正如原始评论中所建议的那样,但也许我会接受教育并学习新的东西。 :-) 编辑,简化了所有内容,现在您可以通过将其设置为属性然后动态更改其位置来移动裁剪蒙版。很明显,你可以用各种精灵层进行爵士乐。
SKSpriteNode *bgImage = [SKSpriteNode spriteNodeWithImageNamed:@"bgImage.png"];
bgImage.anchorPoint = CGPointZero;
[self addChild:bgImage];
cropMaskNode = [SKSpriteNode spriteNodeWithImageNamed:@"clippingImage.png"];
SKCropNode *cropNode = [SKCropNode node];
SKSpriteNode *bgInsideOfCrop = [SKSpriteNode spriteNodeWithImageNamed:@"bgImage.png"];
bgInsideOfCrop.anchorPoint = CGPointZero;
SKEffectNode *effectNode = [SKEffectNode node];
effectNode.filter = [self blurFilter];
effectNode.shouldEnableEffects = YES;
effectNode.shouldCenterFilter = YES;
effectNode.shouldRasterize = YES;
[self addChild: cropNode];
[effectNode addChild:bgInsideOfCrop];
[cropNode addChild:effectNode];
cropNode.maskNode = cropMaskNode;
答案 1 :(得分:0)
根据我的知识,此效果仅适用于ios 7。 Engin Karatepe已将其发布在Github
上- (void)willMoveToSuperview:(UIView *)newSuperview
{
[super willMoveToSuperview:newSuperview];
if (newSuperview == nil) {
return;
}
UIGraphicsBeginImageContextWithOptions(newSuperview.bounds.size, YES, 0.0);
[newSuperview drawViewHierarchyInRect:newSuperview.bounds afterScreenUpdates:YES];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIImage *croppedImage = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(img.CGImage, self.frame)];
UIGraphicsEndImageContext();
self.backgroundImage = [croppedImage applyBlurWithRadius:11
tintColor:[UIColor colorWithWhite:1 alpha:0.3]
saturationDeltaFactor:1.8
maskImage:nil];
}