In the previous post, we have seen how to use the Box2D support into the AGE engine. Now I just want to show you how simple it is to add a new framework/engine support.
For example, we are going to add the Nape support.
For those of you who don’t know, Nape is a Haxe/AS3 physics engine. Since Nape is really close to Box2D, it will be simple to understand how box2d has been added to AGE.
The behavior
Since AGE is based on a behaviors system, we are just going to create a new behavior, that we will call NapeMovementBehavior :
If you have noticed, the world variable is static, because we have to update it on each frame. So to keep the behaviors system intact, we are going to use the BehaviorsManager :
Now to use this behavior with an entity, just add the NapeMovementBehavior to the behaviors list :
1
2
3
4
var e :BasicEntity=newBasicEntity(0,0);e.makeGraphic(32,32,0xFFFF0000);// create a rectanglee.addBehavior(newNapeMovementBehavior(e,true));// add the behavioradd(e);// add the entity to the game
Here is a quick demo (drag the blocks) :
You can see the NapeMovementBehavior class here and the NapeEntity class here.