|
Quickstart
Getting started with b2IDE1. You'll need Box2D.This guide will assume that you already have the AS3 version of the Box2D physics engine, and at least a vague idea of how to use it. If you don't, go get it now, and make sure you can at least compile the examples that come with it. b2IDE has only been tested with Box2D's current release (2.0.1). 2. You'll also need b2IDE.Download the current release, and put the source files in your classpath. (Probably you'll want the b2IDE folder sitting right next to your Box2D folder.) If you haven't already set your classpath to include the b2IDE and Box2D sources, do that now. In Flash, open Edit > Preferences > ActionScript > ActionScript 3.0 Settings, and in the "Source Path" section add the path to the folder containing the b2IDE and Box2D folders. 3. Take a look at hello_world.fla4. Set up your own simulation.Open a new FLA. Create a new MovieClip that will function as your world, called MyWorld or something of the sort. Then, attach your MC to the b2IDE.WorldMC class, by performing the following steps:
Your MC is now attached to b2IDE.WorldMC, and if you don't need to change any parameters then you can finish here. Usually, however, you'll want your MC to inherit WorldMC's parameters, so you can edit them in the IDE. To make this possible:
Now, drag your world MC onto the stage and select it. If you set up the parameters as just described, then in the Component Inspector window you'll see a list of parameters related to the WorldMC, such as gravity, timestep, etc. Most of these parameters correspond directly to variables in the Box2D engine, but a few are specific to b2IDE. See the relevant API reference for details. Once you have a class that extends b2IDE.WorldMC on the stage, you can give it some contents. Create a second MovieClip called "box", and draw a rectangular shape inside it. Then attach this MC to b2IDE.Shapes.BoxMC using the same process you used above. Then, inside your world MC, drag several copies of your box MC to the stage. By default, they all start with a density of 0, so they'll be fixed in place, so in the Component Inspector window, you'll probably want to change the density of some of your boxes to something like 1. Incidentally, once you've added some boxes to your world, feel free to rotate, resize, or skew each box as you like. When b2IDE initializes them to the physics engine, it will create them as polygons with the appropriately transformed shape. Generally, b2IDE attempts to cover all the eventualities this way, so that you can lay things out in the IDE however you like. 5. Test your simulation.That's it! Hit control-enter to test your simulation. If all went well, you'll see several of your boxes on the screen - either fixed in place, if you forgot to give them a non-zero density, or falling into oblivion if you forgot to make a floor. If an error occurred, there's probably a message of some kind traced to the Output window. Check there, or compare your contents to the Hello_World example to see what went wrong. If you're familiar with the Box2D engine, you're probably wondering why you were allowed to add a Shape directly into the world without putting it inside a Body. The answer is that when b2IDE finds bare shapes inside a WorldMC, it automatically generates a BodyMC to contain them. This means that at runtime, the MovieClip you made will no longer be a direct child of the WorldMC, but a grandchild. This is done for convenience, and to maintain the structure of having b2IDE entities to correspond to all Box2D entities, but it's the sort of thing you may need to be aware of. Details like this can be found in the API reference. Once your simulation is working correctly, here are a couple more things to try: Add a Mouse Joint: Define geometry with anchors: 6. Good luck!Have fun, and be sure to report any bugs or feature requests using the "Issues" tab at the top of this site. Thanks for using b2IDE! |
