Thursday, September 10, 2009

simple box2D tutorial

After showing John my latest as-hive integration, he commented that it looked "pretty clunky" and I have to agree. For some reason, the game and physics tests are running very slowly which probably means HIVE is sapping resources somewhere; probably because I was using an old version.



Today, I did another quick tech demo and this time I picked the latest as-hive version 3 which uses the new swc to allow me to work completely in FlexBuilder 3. I should also look at in the Flex Profiler and possibly add some other opensource AS3 memory diagnostic views to make sure version 3 is tight.

This is the second time that I've been inspired by one of Emanuele's great demos, and this time I rewrote it to work more like lego blocks -- IMHO more digestable bites -- and also gave the variables clear English names like "groundBody" or "meteorBallBody".

as-hive and box2d demo

code sample:

public function PhysicsWorld():void
{
createWorld();

drawDebug();
drawGround();
drawBuilding();
drawMeteor();

addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}

full source

I added some comments throughout the code. For instance, if you change the density of the meteor from 100 to 10 it will land peacefully on the roof like a zeppelin but that's another game.

For time to time, we'll try to post small samples like this. Now, onto to skinning the objects and playing with setPixel32 to rip into them.

No comments: