Amit Attias
Amit Attias

Reputation: 143

Masking SKSpriteNode as liquid

I would like to create a liquid dynamics. I searched a lot, created balls moving with device motion, but I don't know how to make the balls look like liquid.. I guess it's some mask but I didn't find how to do it. Could someone help me with that? Thanks.

Upvotes: 4

Views: 787

Answers (2)

Amit Attias
Amit Attias

Reputation: 143

The idea was clear to me. Didn't know what's the actual filter. Figured it out, the SKSpriteNode is nodeWithImage, the image is a blur ball. Physics body is a ball with a smaller body than the image (so the balls can go a little over each other and become "one piece"). The filter of threshold is set on the scene, like that:

CIFilter *filter = [CIFilter filterWithName:@"CIColorPosterize"];
[filter setValue:@(2.0) forKey:@"inputLevels"];
[scene setFilter:filter];
[scene setShouldEnableEffects:YES];

That's it, if anyone ever reads it and has a problem they're more than welcome to message me for help.

Upvotes: 3

Theis Egeberg
Theis Egeberg

Reputation: 2576

Something looking like liquid in games usually follows the following pattern (there are many ways to do this, with filters, shaders, your own custom opengl stuff):

  1. A lot of balls next to each other

  2. Balls have an alpha gradient. So basically if you do a radial gradient in photoshop on the alpha channel with black color you get a very blurry ball. Or just draw a black ball in photoshop and blur it. You get the point.

  3. You hard contrast (threshold) everything. In effect what this does is at a certain threshold it does either 1.0 alpha or 0.0 alpha. So either on or off.

enter image description here

Upvotes: 5

Related Questions