【发布时间】:2014-07-06 15:31:26
【问题描述】:
我正在尝试为我的游戏中的节点添加磨砂玻璃效果。例如http://bit.ly/1vNMvAG 这样做的正确方法是什么?
【问题讨论】:
标签: ios xcode sprite-kit
我正在尝试为我的游戏中的节点添加磨砂玻璃效果。例如http://bit.ly/1vNMvAG 这样做的正确方法是什么?
【问题讨论】:
标签: ios xcode sprite-kit
我一定是遗漏了一些东西,因为我会按照原始 cmets 中的建议留在 SpriteKit,但也许我会接受教育并学习新的东西。 :-) EDIT,简化了一切,现在您可以通过将裁剪蒙版设置为属性来移动裁剪蒙版,然后随时动态更改其位置。显然你可以用不同的精灵层来增加它的活力。
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;
【讨论】:
据我所知,此效果仅在 ios 7 中可用。 Engin Kurutepe 已将其发布在 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];
}
【讨论】: