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

Quick Switch Flash game prototype made with Box2D

A simple and addictive game which is interesting to deconstruct is Quick Switch. Use your mouse to hover over and activate platforms to guide your ball to the target.

In the making of this prototype, I’ll be using all body types Box2D allows me to use, so we have:

Static Bodies: will be used for platform which are always active

Dynamic Bodies: will be used for the ball

Kinematic Bodies: will be used for platform which need to be activated. If you don’t know what is a kinematic body, read understanding Box2D kinematic bodies.

To simplify the process of level design, I will start from the project basic Box2D editor using Flash movieclips.

So this is the final script:

And this is the result:

Hover the mouse over purple platform to make them solid and drive the ball into the green goal.

Now, let’s see the interesting part of this script, which is update function:

Line 85: looping through all bodies

Line 86: now it’s time to make different things according to body type

Lines 87-92: it’s a dynamic body (the falling ball): I just put it in its starting place if it falls down the stage

Lines 93-97: it’s a kinematic body (an activable platform): I turn it into a sensor. It’s the best thing to do to make it “transparent”. It does not react to collision.

Line 100: Now it’s time to check for mouse position and check for bodies under the mouse with queryCallback function.

This function simply scans for all fixtures inside the body under the mouse and does not make them sensors anymore.

And that’s it.

Download the source code.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (8 votes, average: 5.00 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 one comment

  1. Quick Switch Flash game prototype made with Box2D – Emanuele Feronato « eaflash

    on November 26, 2012 at 10:46 am

    [...] on http://www.emanueleferonato.com Share this:TwitterFacebookLike this:LikeBe the first to like [...]