Understanding pixels and meters with Box2D and how to select an object with mouse – part 1

Emanuele Feronato Actionscript 3, Box2D, Flash, Game design

This will be the longest post title in blogging history… anyway I am about to explain you two things that seem to be still unclear about AS3 version of Box2D.

The first one is Box2D measuring units that may seem weird until you realize Box2D works with meters where 1mt = 30 pixels.

The second one is the capability of selecting single objects with the mouse thanks to the custom GetBodyAtMouse. There are even people willing to pay for those information in the official forum.

So I modified the HelloWorld example in my own way in order to have some 90×90 ox sided crates (texture by http://www.reallyreallygoodthings.com/) I can make “jump” and “torque” clicking the mouse on them.

This is the uncommented actionscript, I will post the step-by-step explaination tomorrow.

and this is the result:

Click on a crate to make it jump and torque. Download the source code and wait for the step-by-step tutorial.

From null to full HTML5 cross platform game

I will take you by hand from the bare bones of JavaScript programming through the creation of a full cross platform HTML5 game, with detailed explainations and source code.

If you don't know where to start, then From null to full HTML5 cross platform game is the book for you.

Comments 19

  1. Pingback: Understanding pixels and meters with Box2D and how to select an object with mouse - part 2 : Emanuele Feronato

  2. Pingback: Prototype of a Flash game like Meeblings : Emanuele Feronato

  3. Pingback: Scaling objects with Box2D : Emanuele Feronato - italian geek and PROgrammer

  4. Prashant

    I have download the source file.

    and also Box2d zip folder.

    and i have a error
    1046:Type was not found or was not a compile-time constant: b2Body

    i am new in as3


  5. oscar

    I download you example, but it don’t work because flash don’t find b2PolygonDef. I download the latest Box2D, exactly Box2DFlashAS3 2.1a … (others examples work fine, because they haven’t b2PolygonDef)

    can you help me? Thanks

  6. Cassandra

    Really good post and you are doing best in box2d. I am not able to understand getBodyAtMouse function fully.

    can you help me?

  7. Pingback: Flash Game Development Inter-web mash up: Nov 20, 2008 « 8bitrocket.com

Leave a Reply

Your email address will not be published. Required fields are marked *