PhysicsJS

Getting Started

You can use PhysicsJS as an AMD module (requireJS), a CommonJS module, or a regular browser global.

As an AMD Module with requireJS

This is the recommended way to use PhysicsJS. Read about requireJS to learn how to set it up.

Tell requireJS where to find the PhysicsJS source.

require.config({
    baseUrl: './',
    // ...
    packages: [
        {
          name: 'physicsjs',
          location: 'path/to/physicsjs',
          main: 'physicsjs-VERSION.min'
        }
    ],
    //...
});

Now require the dependencies you need.

require([
    'physicsjs',
    'physicsjs/bodies/circle' // will mix into the PhysicsJS library
], function( Physics ){

    // do something fun with circles!
});

As a browser global

Simply include the library in your html.

<script src="scripts/physicsjs/physicsjs-VER.min.js"></script>

Start using it.

Physics(function(world){
  // code...
});

PhysicsJS was made to be modular. So any non-core functionality is separate and must be included separately. For example, if you want circles, you would have to include that script after including PhysicsJS.

<script src="scripts/physicsjs/physicsjs-VER.min.js"></script>
<script src="scripts/physicsjs/bodies/circle.js"></script>

This could get quite tedious, which is why using requirejs (and its optimizer) is recommended. However, if you know you’ll want most or all extras, you can use the “full” version of the script, which includes all non-core functionality.

<script src="scripts/physicsjs/physicsjs-full-VER.min.js"></script>

As a node.js (commonJS) module

This has not yet been tested but it should be entirely possible to run PhysicsJS in node.js by requiring the correct file.

var Physics = require('./path/to/physicsjs/physicsjs-full-VERSION');

Physics(function(world){
  // code...
});