Build 10 games and learn game development along the way in this fast paced game development course

Get the source code of 12 commercial games, loaded 50+ million times, and learn the secrets of game design

Learn how to make a successful Flash game from a real world example. Fully commented source code

Create realistic Flash physics games from scratch with advanced features, from Angry Birds to Crush the Castle

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 (11 votes, average: 4.91 out of 5)
Loading ... Loading ...
Learn how to make a successful commercial Flash game from a real world example: get the fully commented source code of Globez, a Flash game played millions of times which generated a four figure income. Limited copies available.

Get it now
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 2 comments

  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 [...]

  2. Quick Switch Flash game prototype made with Construct2 - Emanuele Feronato

    on August 6, 2013 at 6:31 pm

    [...] time passed since I published the Quick Switch Flash game prototype made with Box2D, so it’s time to show the same thing made with Construct2, to make you see how easy is to [...]

Thank you for the download!!

I hope you will find it useful and make something interesting out of it

To keep up to date with the blog, why don't you like my Facebook page and follow me on Twitter?

Want to learn more? Don't miss this:

Learn how to make a successful commercial Flash game from a real world example: get the fully commented source code of Globez, a Flash game played millions of times which generated a four figure income. Limited copies available.

Get it now

×