Talking about Actionscript 3, Box2D and Flash.
When you are about to design a level or whatever else in Box2D, you have to face some design issues due to different unit measurements (Flash works with pixels while Box2D uses meters) and the common problems in level design: the need to have a WYSIWYG interface.
Some frameworks such as Citrus Engine, have a built in editor, but what if you are making a Box2D project on your own?
I am making a little Box2D editor to be used in a couple of games I am making, and it’s based on… Flash movieclips.
It’s the easiest solution if you don’t need a lot of features. The best solution for simple games such as Totem Destroyer.
It works this way: first, we need a movieclip with a box, centered in its origin:
Then using this movieclip, we start building the level in another movieclip just adding and transforming the original box movieclip:
Finally, we need to tell the movieclip which boxes are static and which ones are dynamic: I am giving a d
instance name for dynamic boxes and a s
instance name for static boxes.
Then it’s just actionscript:
package {
import flash.display.Sprite;
import flash.events.Event;
import Box2D.Dynamics.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.Math.*;
public class b2ded extends Sprite {
// this is the size of the original box movieclip
public var box_original_size:int=40;
// importing the editor movieclip
public var editor:editor_mc = new editor_mc();
public var world:b2World=new b2World(new b2Vec2(0,10.0),true);
public var world_scale:int=30;
public function b2ded():void {
debug_draw();
// placing the editor movieclip in transparency to show its precision
addChild(editor);
editor.alpha=0.2
// looping through all children in the editor movieclip
for (var i:int=0;i
And this is the result:
As you can see I perfectly recreated the Box2D environment I made in the editor movieclip.
Obviously it's far from being complete, but you can add more features just playing with instance name, adding attributes such as density, restitution and so on. If I receive a good feedback, I can improve the editor or share the one I am making for my games.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.