DevBlog - Making a Mapeditor

Posted in | »

DevBlog - Making a Mapeditor

Okay so you've seen and played a minimalistic demo of movement in the game. Now if any of you are familiar with physics API's, you know that making a modell by hand in them can be very daunting. For example adding a simple box to the physics modell can look like this:

var bodyDef:b2BodyDef = new b2BodyDef();
bodyDef.position.Set(x*INV_PHYS_SCALE, y*INV_PHYS_SCALE);
bodyDef.angle = _parent.rotation / 180 * Math.PI;

var body:b2Body = m_world.CreateDynamicBody(bodyDef);

var box:b2PolygonDef = new b2PolygonDef();

box.SetAsBox(50*INV_PHYS_SCALE, 50*INV_PHYS_SCALE,

box.density = 1.0; //these should be variables in the component definition
box.friction = 0.4;
box.restitution = 0.3;
body.CreateShape(box);
body.SetMassFromShapes();

That is creating one (1) box. So you can imagine that making a whole level with enemies, that also fits to a illustrated background could take it's time. That's why you create a map editor!

I usually do this by making a separate .fla, just containing a bunch of repressentative movieclips, one for each element I want in the game. In this the elements are amongst others: player's tank, static rectangles and circles, enemies, dynamic boxes etc.

To make a map you simple make a crude representation of how you want it to be with your movieclips. Then you add some simple code to the first and only frame of the mapeditor.fla, which goes through all childs to that frame, and traces a bunch of lines repressenting the code needed to add that object to the physics engine. Finally, cody and paste all the generated code from the output into a suitable place int your game engine, and you're good to go.

Wunderbaum!

Submitted by Fickludd on Sat, 05/10/2008 - 18:56