1 decade ago by alexandre
How would I go about writing a plugin module of utility functions--say for Box2D--something I could use like
I tried this:
But nope. Seems like
triggers an "Unexpected identifier" error.
Obviously a JS misunderstanding on my part.
var myDisc = Box2dUtils.makeDisc({x:100, y:100},20,1,0,0,myWorld);
I tried this:
ig.module ( 'game.box2d-utils' ) .requires ( 'plugins.box2d.debug', 'plugins.box2d.game', 'plugins.box2d.entity' ) .defines (function () { makeBox: function (pos, size, density, restitution, friction, world) { var bodyDef = new b2.BodyDef(); bodyDef.position.Set ( pos.x * b2.SCALE, pos.y * b2.SCALE ); var body = world.CreateBody(bodyDef); var shapeDef = new b2.PolygonDef(); shapeDef.SetAsBox ( size.x / 2 * b2.SCALE, size.y / 2 * b2.SCALE ); shapeDef.density = density; shapeDef.restitution = restitution; shapeDef.friction = friction; body.CreateShape(shapeDef); body.SetMassFromShapes(); return body; }, makeDisc: function (pos, radius, density, restitution, friction, world) { var bodyDef = new b2.BodyDef(); bodyDef.position.Set ( pos.x * b2.SCALE, pos.y * b2.SCALE ); var body = world.CreateBody(bodyDef); var shapeDef = new b2.CircleDef(); shapeDef.radius = radius * b2.SCALE; shapeDef.density = density; shapeDef.restitution = restitution; shapeDef.friction = friction; body.CreateShape(shapeDef); body.SetMassFromShapes(); return body; } });
But nope. Seems like
makeBox: function (pos, size, density, restitution, friction, world)
triggers an "Unexpected identifier" error.
Obviously a JS misunderstanding on my part.