Reputation: 1345
I am trying to use ripple effect in spritekit. Here I have written code for ripple is
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CATransition *animation=[CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.75];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[animation setType:@"rippleEffect"];
[animation setFillMode:kCAFillModeRemoved];
animation.endProgress=0.99;
[animation setRemovedOnCompletion:YES];
[self.view.layer addAnimation:animation forKey:nil];
}
By using this code when I am touching anywhere in the screen an one wave ripple arise. But I want to make ripple effect specifically on a node. Like 10 radius circle around the touching point on the screen.
Please help. Thanks in Advance.
Upvotes: 4
Views: 1239
Reputation: 126107
Core Animation effects work at the level of Core Animation layers, and your Sprite Kit view is one layer regardless of what goes on in terms of scenes and nodes within it.
To apply similar kinds of effects on only a part of the Sprite Kit node hierarchy, you can use the SKEffectNode
class, which can apply a Core Image filter to the results of rendering its child nodes. For animation, you can adjust filter parameters over time in your scene's update:
method.
The catch to this is that there's no convenient way to use it for a ripple effect, specifically: CIRippleTransition
is a transition filter, not a single-image-input filter, and you can only use the latter kind with SKEffectNode
. Varying CITorusLensDistortion
parameters over time might make a decent substitute, though.
Upvotes: 1