Talking about Actionscript 3, Box2D, Flash and Game development.
As said, we’re going to create a little game with Citrus Engine.
Since the engine it’s ready, we can start with level design.
So let’s open the Citrus Engine Level Architect, included in the package, and let’s start playing with it.
The key of this little tool is the right mouse key. Pressing it will open a menu with all available assets.
Choose Platform
and you will be able to create static Box2D boxes.
Now click anywhere with left mouse button and a black square will appear: that’s the platform. Drag and adjust it as you want.
Don’t worry about extreme precision: we’ll retouch it later. Once you placed some platforms, from the right click menu choose and place the hero, a coin and a couple of crates. Crates represent dynamic Box2D objects. This is what I’ve made:
Then select File->Save Level As
and save your level. Don’t worry about the path: despite what suggesting in the official docs we won’t include external XML files. We are making a game to distribute it, so we need a single file.
Edit the created XML file removing this line
and eventually rounding the x
, y
, width
and height
attributes of your assets.
This is my final XML:
Then drop a few AS3 lines:
package {
import flash.display.MovieClip;
import com.citrusengine.core.CitrusEngine;
import com.blueflamedev.math.*;
public class citrusdemo extends MovieClip {
public function citrusdemo() {
var level_xml:XML =
;
var ce:CitrusEngine=CitrusEngine.getInstance();
ce.initialize(this);
ce.camera.debugDraw=true;
ce.physics.gravity=new MathVector(0,900);
ce.loop.run(this);
ce.manager.createSet("Level 1",XML(level_xml));
}
}
}
Lines 7-17: Importing the XML
Lines 18-19: Initializing the engine
Line 20: Turning on debug draw
Line 21: Defining the gravity. I found MathVector(0,900)
very similar to b2Vec(0,10)
Line 22: Starting the simulation
Line 23: Loading the XML level
And that’s it:
Move your hero with arrow keys and jump with spacebar. Try to get the coin.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.