2.0.0 • Published 13 years ago

box2dnode v2.0.0

Weekly downloads
7
License
-
Repository
github
Last release
13 years ago

Box2DNode

@author Benjamin de Jager m0rph3v5@gmail.com

A port of the latest box2djs library into a node module.

How to install

npm install box2dnode

How to use

A simple example below, you can check the documentation of box2d itself to do other stuff http://www.box2d.org/

var b2d = require("box2dnode");

var world = new b2d.b2World(
		new b2d.b2Vec2(0, -10), // gravity
		true 				// dosleep
	);
	
var bodyDef = new b2d.b2BodyDef;
bodyDef.type = b2d.b2Body.b2_dynamicBody;
bodyDef.position.Set(0.0, 4.0);

var body = world.CreateBody(bodyDef);

var dynamicBox = new b2d.b2PolygonShape;
dynamicBox.SetAsBox(1.0, 1.0);

var fixtureDef = new b2d.b2FixtureDef;
fixtureDef.shape = dynamicBox;
fixtureDef.density = 1.0;
fixtureDef.friction = 0.3;

body.CreateFixture(fixtureDef);

function update() {
	world.Step(1/30, 10, 10);
	console.log(body.GetPosition());
}
setInterval(update, 1000/60);