Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 281
Amit Attias Avatar asked Feb 12 '23 22:02

Amit Attias


2 Answers

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

like image 57
Theis Egeberg Avatar answered Feb 25 '23 05:02

Theis Egeberg


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.

like image 43
Amit Attias Avatar answered Feb 25 '23 05:02

Amit Attias