Box2d Editor

September 23rd, 2007

While I was finishing up the game logic part of my second LineWorld experiment, I discovered I HATED manually creating levels by hand (i.e C++ code)

So I decided to design a simple “draw and export” tool that allowed the current Box2D world to be exported into C++ AND Lua.

Binaries and source available at SourceForge. Please use CVS to get the latest source as the .zip files will be at least a version behind.

Unfortunately, joints aren’t supported yet (almost). The sample C++ export code looks something like this:

//Box 2d Editor export by Casually Hardcore Games Inc.
b2Body* b0 = NULL;
{
b2BoxDef sd;
sd.extents.Set(2.5,5);
sd.density = 0;
sd.friction = 0.2;
sd.restitution = 0;

b2BodyDef bd;
bd.position.Set(-117.887,21.2296);
bd.rotation = 0;
bd.AddShape(&sd);
b0 = world->CreateBody(&bd);
}
b2Body* b1 = NULL;
{
b2BoxDef sd;
sd.extents.Set(2.5,5);
sd.density = 0;
sd.friction = 0.2;
sd.restitution = 0;

b2BodyDef bd;
bd.position.Set(117.651,17.0501);
bd.rotation = 0;
bd.AddShape(&sd);
b1 = world->CreateBody(&bd);
}
b2Body* b2 = NULL;
{
b2BoxDef sd;
sd.extents.Set(2.5,5);
sd.density = 0.5;
sd.friction = 0.5;
sd.restitution = 0.1;

b2BodyDef bd;
bd.position.Set(-111.602,20.6748);
bd.rotation = -0.361298;
bd.AddShape(&sd);
b2 = world->CreateBody(&bd);
}

The Lua looks like this:

-- Box 2d Editor export by Casually Hardcore Games Inc.
local box2d = Musicala.Box2dManager:getSingletonPtr()
local world = box2d:getWorld(0)
local box = b2BoxDef()
local circle = b2CircleDef()
local poly = b2PolyDef()
local bd = b2BodyDef()
box = b2BoxDef()
box.extents:Set(2.5,5)
box.density = 0
box.friction = 0.2
box.restitution = 0
bd:AddShape(box)

bd.position:Set(-114.571,20.2334)
bd.rotation = 0
local body0 = world:CreateBody(bd)
bd = nil
bd = b2BodyDef()

box = b2BoxDef()
box.extents:Set(2.5,5)
box.density = 0
box.friction = 0.2
box.restitution = 0
bd:AddShape(box)

bd.position:Set(114.187,18.812)
bd.rotation = 0
local body1 = world:CreateBody(bd)
bd = nil
bd = b2BodyDef()

box = b2BoxDef()
box.extents:Set(2.5,5)
box.density = 0.5
box.friction = 0.5
box.restitution = 0.1
bd:AddShape(box)

bd.position:Set(-108.263,19.8568)
bd.rotation = -0.273016
local body2 = world:CreateBody(bd)

Entry Filed under: Game Development

Leave a Comment

You must be logged in to post a comment.

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

September 2007
S M T W T F S
« Aug   Nov »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Most Recent Posts