Skip to content

Box2DWeb and Box2DJS custom exporter for PhysicsEditor (CodeAndWeb)

Notifications You must be signed in to change notification settings

aashby13/box2dweb-exporter-physicseditor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 

Repository files navigation

box2dweb-exporter-physicseditor

Custom exporter for Box2DWeb for use with PhysicsEditor from CodeAndWeb
Exported script is an ES6/2015 module

By default, the script is set up to import the ES2015 Module, box2dweb-haircut:
https://www.npmjs.com/package/box2dweb-haircut

The import of a CommonJS module of Box2DWeb is included in the comments:
https://www.npmjs.com/package/box2dweb

If you need an ES5 version, download version 1.0.2

Directions:

  • Set your custom exporter directory in your preferences for PE.
  • Place the folder named box2d-js-es6 in your custom exporter directory.
  • After publishing and adding the script to your app, create the bodies like so:

    import Box2D from 'box2dweb-haircut';
    import PhysicsData from 'PhysicsData';

    /*
        PE default ptm ratio is 32 and can be edited in the PE UI.
        If you need to adjust the ptm ratio after publishing, plug the number into the constructor
    */
    const physicsData = new PhysicsData(64);

    /* created your bodies - args: bodyName, world, bodyType, userData */
    const brainBody = physicsData.createBody('brain',
        world,
        Box2D.Dynamics.b2Body.b2_dynamicBody,
        {
            sprite: brainSprite,
            ratio: 64,
            update: b => {...}
        }
    );