Lucy b2
Box2D by Erin Catto with google's particle simulation
liquidfun for node.js.
This fork
Fork from box2d.js.
Due to the fact that we are not creating sub-classes of C++ classes, we do not
need to use 'b2' prefix to separate namespaces so this prefix has been removed.
const b2 = require ( 'lucy-b2' )
let gravity = new b2.Vec2 ( 0, -9.8 )
let world = new b2.World ( gravity )
let shape = new b2.PolygonShape
Documentation
Example
Here is a falling ball simulation.
'use strict'
const b2 = require ( 'lucy-b2' )
let gravity = new b2.Vec2 ( 0, -9.8 )
let world = new b2.World ( gravity )
let bodyDef = new b2.BodyDef
bodyDef.type = b2.BodyType.dynamicBody
let body = world.CreateBody ( bodyDef )
let fixDef = new b2.FixtureDef
fixDef.density = 1.0
fixDef.friction = 0.2
fixDef.restitution = 0.8
let shape = new b2.PolygonShape
shape.SetAsBox ( 0.1, 0.1 )
fixDef.shape = shape
body.CreateFixture ( fixDef )
body.SetTransform ( 0, 2, 0 )
for ( let i = 0; i < 10; i++ )
{ world.Step ( 1/60, 10, 10 )
console.log ( body.GetPosition ().y )
}
Installation
npm install lucy-b2 --save
Tests
npm test
Contributing
Please see box2d.js for contributions.
The port from this library is just a few Regexp executed on the minified JS
version and a wrapper for node.js.
Please use 'jessy style' if you want to
write some unit tests for lucy-b2...
Release History
- 1.0.1 (2015-09-22) Fixed readme.
- 1.0.0 (2015-09-09) Initial release.