Water

Has anyone had any luck modelling water?

m

I'm on it, some very interesting things are happening. I'll show you what i have when it's worth showing

I'm desperate to know a good way to do this. My first attempt was to put 1000 small circles with physics bodies attached and drop them into a square container. It worked, but it won't run with anything else and on the iPad device it ran like a dog...

box2d has a bouyancy controller but it doesn't look like it's exposed in corona

Try images instead of vectors. Look at the fishies example. It is one image. Loaded multiple times. Takes less amount of memory. Could you try that and see what the p4mance is?

C

If the goal is to actually model water itself...you're basically talking fluid dynamics, which is "extremely computationally intensive". It's the kind of thing that a console game would devote an entire PS3 processor unit to simulating, and it still wouldn't be very realistic.

As noted, you might be able to get interesting low-resolution fluid effects from a bunch of small, circular Box2D objects (the circular bodies should be the lightest load on the engine). Like Carlos says, use bitmaps rather than vector objects for faster rendering. It doesn't sound like 1000 objects is workable, but maybe a couple hundred?

If the goal is to model the behavior of underwater objects, then that's more feasible.

I guess I'm being ignored ;)...I mentioned earlier that Box2d has a bouyancy controller in the source distrib.
It works great if corona just provided an interface.

Ah, here's an odd one then... I'm not actually looking to model water per se- in fact I'm really just wanting to have lots and lots of little blue lines (or 2px high rectangles) all wibbling around like they're trying to escape, bouncing off each other (though not with much energy) and dropping onto the object below when they reach the edge of the thing they are currently sitting on.

I thought of the physics engine / Game Edition when thinking about this because it is 'water-like' and involves many individual 'bodies'. Also, gravity needs to be applied to them.

I guess the best equivalent is actually a particle system, with gravity applied...

One idea involving a bunch of little circles all combined is this. I have some code here involving creating a set number of objects in a "columns and rows" fashion. You can create a ton of tiny little blue balls (just don't go overboard by adding 1400 or more things. 1400 such objects alone can really demand a lot on the thing) in such a manner and have them "pour" into a cup or whatever. Stuff won't be able to sink in them but you will get a seemingly water-like visual effect. Here's the code:

1
2
3
4
5
6
7
8
9
local balls = {}
 
for i = 1, 10 do
        for j = 1, 110 do
                balls[i] = display.newCircle( 140 + (i*50), 220 - (j*50), 2 )
                balls[i]:setFillColor( 0, 127.5, 255 )
                physics.addBody( balls[i], { density = 0.1, friction = 0.1, bounce = 0, radius = 2 } )
        end
end
views:1807 update:2011/10/4 8:06:35
corona forums © 2003-2011