Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

latest version of box2d for nodejs

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 Box2D.js
Octocat-spinner-32 Readme.md
Octocat-spinner-32 package.json
Readme.md

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);

Something went wrong with that request. Please try again.