2

I'm trying to add frosted glass effect for nodes in my game. For example http://bit.ly/1vNMvAG What is the right way to do that?

user3785463
  • 119
  • 1
  • 8

2 Answers2

1

I must be missing something, as I would just stay with SpriteKit, as suggested in original comments, but maybe I'll get schooled and learn something new. :-) EDIT, simplified everything, and now you can just move the crop mask by setting it as a property and then changing its position dynamically as you go. Obviously you could jazz it up with various sprite layers.

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;
Cooper Buckingham
  • 2,503
  • 2
  • 15
  • 23
  • Unfortunately, this doesn't work. I just see transparent node. – user3785463 Jul 07 '14 at 09:27
  • I can't help you if you don't help yourself. The code above works great. I don't know what "only see a transparent node means". But it sounds like you missed a step. – Cooper Buckingham Jul 07 '14 at 09:32
  • I need something like iOS7 effect. There is UIToolbar in UIKit and I can change its shape using CALayer, but its not real to mix it with SpriteKit. – user3785463 Jul 07 '14 at 09:36
  • It sounds like you're still confused. I can't go back in forth in comments again. I took the time to give you a pretty great step by step solution. You can tailor it with however you'd like your blur effect plus an optional frosted layer to look. I wish you the best of luck. :-) – Cooper Buckingham Jul 07 '14 at 09:48
  • This is the correct approach in my opinion, thanks for posting it! – Howard Cohen Nov 21 '15 at 01:24
0

this effect is only available in ios 7 to my knowlwdge. Engin Kurutepe has posted it on 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];
}

Code Sample Ref

Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81