Build 10 classic Flash games and learn game development along the way with this ultra-fast paced game development course.

If you love this blog, this is the book for you.

Buy the book

Get the source code of 12 commercial Flash games, which have been loaded more than 50 million times!

Learn from real world successful examples.

Get it now

Box2D for Flash Games teaches you how to make Flash physics games from scratch with the most advanced features.

Create the new Flash game smashing hit.

Buy the book

Using Box2D buoyancy controller to create a pool

If you watched all demos in the official Box2D AS3 page, you should know you can achieve buoyancy effect using a buoyancy controller.

I played a bit with it, and I wasn’t satisfied your controller must cover the entire world, just allowing you to limit it with an offset. It would have been way better if you could define an area in which bodies are affected by buoyancy controller. This way you could create a pool.

Look at this example:

Click with the mouse to release a random box from the top at mouseX position. You will see only bodies falling in the “pool” are affected by buoyancy controller.

The trick is made by creating a sensor with the same shape of the desired buoyancy controller, and adding bodies to the controller only if they touch the shape.

This way you can create pools

Look at the source code:

The code is not commented because I play to optimize it a bit, but if you have doubts, just ask. You can also download the source code.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (8 votes, average: 4.88 out of 5)
Loading ... Loading ...
Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 3 comments

  1. siddharth shekar

    on February 25, 2013 at 7:45 am

    Great thanks… now how can I create ripples? I once tried faking it with sine and cos functions. But didnt look that great What is the standard/good way achieve a believable result? Thanks. And as usual awesome tutorials.

  2. Fábio Colombini

    on February 25, 2013 at 9:46 am

    Thanks Emanuele, great example!

  3. earthwormjeff

    on February 26, 2013 at 8:51 am

    Thanks for this nice example. I suggest to use the contact listener between the sensor and the falling bodies (BeginContact and EndContact) to attach or detach to the buoyancyController.