Way of an Idea Box2D prototype – Step 2

It’s time to apply the concepts seen at Pausing a Box2D simulation with Way of an Idea Box2D prototype to create a paused Box2D simulation that will start only when you’ll press SPACE, and meanwhile you can draw paths, just like in the original game.

The only problem with this technique is you can’t use the debug draw to test your projects, because debug draw draws only after Step function has been executed, and since the game starts with the simulation paused, you can’t see the Box2D boxes you are drawing (and you can’t even see other assets too) until you start the simulation.

So the trick is: placing the Box2D boxes, the ones debug draw won’t draw, and attaching the movieclips to them. The movieclips will be rendered because I am adding them to stage, and they will remain in position until the simulation starts.

So the script becomes:

and this is the result:

draw with the mouse and press SPACE to play/pause the simulation.

Download the source code.

Next step, chalk management and goal.

  • Vadersapien

    Looking a lot like line rider, but with box2d…if you replaced the circle with a compound object and added an eraser…I think that’d make an interesting game…

  • Pingback: Way of an Idea Box2D prototype – Step 3 : Emanuele Feronato - italian geek and PROgrammer()

  • xraven13

    Hi, there..
    Thank you for this article, because of it i am making new game that will use this concept…

    Problem is that i am stuck ^^…
    When i draw on screen and drawing transforms to b2 objects they don’t appear exactly where trace of “pen” is, but they appear a little down and to the right.. Closer i draw to the right part of the screen objects move more to the right…
    I am sure this doesn’t have anything with gravity..

    What is interesting is that this happens even when update of b2World is not running.. :/
    And btw, pause will not be solution since i need to draw objects while b2World is running because i am creating action game that will use this drawing object technique…

    Thanks in advance for your answer.. Please email me.

    Cheers,

    Kristian

  • xraven13

    I think this could be connected with ratio..
    U are dividing positions by 60…
    I tried to use my RATIO that i use everywhere but it doesn’t work, though i get different placements then…
    Any idea how to make this work?
    p.s. u really should have that value as constant it would be easier to understand what’s happening :p

    Cheers!

  • xraven13

    Sigh now it starts too look like i am spamming you..
    But u might get some extra traffic because of this :D
    Anyway i played a little with values and it seems part of problem is in this part :
    create_box((sx+ex)/World.RATIO,(sy+ey)/World.RATIO,Math.abs(dist)/World.RATIO,2/30,angle);

    When i change sx+ex to sx and sy+ey to sy then body its placed where it should be placed, BUT…
    Bodies are not 1 after another but they are more like half of each inside of other..Not sure how to explain it…I tried reducing width by 2 but it didnt help..

  • xraven13

    Screenshot of problem :
    http://tinypic.com/r/eambzk/5

  • Hello,
    I would like to kindly ask you advice (paying your dues!):
    I’ll explain, I would like to create a test application for iPhone (tamite Flash Pro CS6), once
    created the file. ipa, I try to insert it on the iPhone via itunes without success and without any error message
    how is it possible?

    Procedure:

    – I open Flash Pro CS6
    – Create new document Air for iOS
    – Then I’m going to change application settings
    – Insert my certificate iphone_dev.p12
    – I put on my provisioning profile file *****. Mobileprovision
    – Then I go on Public
    – .. And after a while I pull out my file. Ipa

    I await your kind response
    greetings
    Fausto