npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clonable-planck-js

v0.1.44

Published

2D JavaScript physics engine for cross-platform HTML5 game development

Downloads

1

Readme

Planck.jsα

Planck.js is JavaScript rewrite of Box2D physics engine for cross-platform HTML5 game development. Check out demos!

Car

Motivations

Key motivations for the development of this project are:

  • Taking advantage of Box2D's efforts and achievements
  • Developing readable and maintainable JavaScript code
  • Optimizing the library for web and mobile platforms
  • Providing a JavaScript-friendly API

Try it

To try Planck.js, simply add planck-with-testbed.js script to your HTML code and call planck.testbed(callback) with your code in callback. For example:

<html><body>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/planck-with-testbed.js"></script>
  <script>
    planck.testbed(function(testbed) {
      var world = planck.World();
      // rest of your code
      return world; // make sure you return the world
    });
  </script>
</body></html>

Check out Car example on JS Bin to try it in practice. Also see example directory for more testbed usage examples.

Install

To receive updates about changes and progress follow @piqnt on twitter.

Download

Latest builds are available on releases page.

CDN

Planck.js is available on jsDelivr.

NPM

npm install planck-js --save

Bower

bower install planck-js --save

Usage

Planck.js does not use any renderer by default. To use or integrate it with a rendering library all you need to do is call world.step(timeStep) in each frame, and then iterate over world entities to draw or update them. You may also want to listen to world events to remove objects which are removed from the world. For example:

<script src="./path/to/planck.min.js"></script>
<script>
  var world = planck.World();

  window.requestAnimationFrame(function() {
    // in each frame call world.step(timeStep) with fixed timeStep
    world.step(1 / 60);
    // iterate over bodies and fixtures
    for (var body = world.getBodyList(); body; body = body.getNext()) {
      for (var fixture = body.getFixtureList(); fixture; fixture = fixture.getNext()) {
        // draw or update fixture
      }
    }
  });

   world.on('remove-fixture', function(fixture) {
    // remove fixture from ui
  });
</script>

API

Planck.js public API closely follows Box2D API (see Resources), with the following differences:

  • b2 prefix is dropped from class names, for example b2World is now available as planck.World.
  • Method names are converted from UpperCamelCase to lowerCamelCase.
  • Definition classes/objects (BodyDef, FixtureDef, etc.) are replaced by inline JavaScript objects ({}).
  • Shapes are made immutable and are not cloned when used to create fixtures.
  • World#on(eventName, listenerFn) and World#off(eventName, listenerFn) are added to add and remove event listeners. Currently supported events are:
    • 'begin-contact'
    • 'end-contact'
    • 'pre-solve'
    • 'post-solve'
    • 'joint-removed'
    • 'fixture-removed'
    • 'body-removed'

Resources

  • Box2D Manual and FAQ are highly recommended to get started.
  • iforce2d website includes a collection of helpful tutorials and resources to learn Box2D.

Following resources are recommended if you are interested in learning about Box2D/Planck.js's internal details.

If you know any other useful resource, please add it or submit an issue.

Testbed

Another way to use testbed and try included examples (in example directory) is running testbed with live build locally:

  1. Install git and npm

  2. Clone or download this repository

  3. Install npm and bower dependencies:

     npm install
  4. Run testbed and open it in your web browser (see command-line output for URL to open):

     npm run testbed

Architecture

Planck.js includes Box2D algorithms without modification and its internal architecture and public API are very similar to Box2D. However some changes and refactoring are made during rewrite to address differences between C++ and JavaScript.

Credits

Box2D is a popular C++ 2D rigid-body physics engine created by Erin Catto. Box2D is used in several popular games, such as Angry Birds, Limbo and Crayon Physics, as well as game development tools and libraries such as Apple's SpriteKit.

Planck.js is developed and maintained by Ali Shakiba.

License

Planck.js is available under the zlib license.