Planck.js is JavaScript (TypeScript) rewrite of Box2D physics engine for cross-platform HTML5 game development.
- 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
- Documentation Wiki - This is the best place to start, and find other resources
- Examples - Online examples with editable code
- Discord - Community discussions and Q/A
- Twitter @Piqnt - Updates and news
- GitHub - Source code and issues
Planck.js includes Box2D algorithms without modification and its architecture is very similar to Box2D. However some internal changes and refactoring are made during rewrite to address differences between C++ and JavaScript.
Planck.js public API closely follows Box2D API, with the following differences:
b2
prefix is dropped from class names, for exampleb2World
is now available asplanck.World
.- Method names are converted from UpperCamelCase to lowerCamelCase.
- Definition classes/objects (BodyDef, FixtureDef, etc.) are replaced by inline JavaScript objects (
{}
). - Shapes are considered immutable and are not cloned when used to create fixtures.
- Contact filtering can be customized by overriding shouldCollide method of Fixture.
- Listener classes are replaced with simple functions.
World#on(eventName, listenerFn)
andWorld#off(eventName, listenerFn)
are added to add and remove event listeners. Currently supported events are:'begin-contact'
,'end-contact'
,'pre-solve'
,'post-solve'
,'remove-joint'
,'remove-fixture'
,'remove-body'
Staring from v1.0 package name is changed to planck
.
Releases and updates before v1.0 will remain available under planck-js
package name.
Planck.js is available on jsDelivr.
Install npm package.
npm install planck
Import it in your code.
import * as planck from 'planck';
Use CDN in a web page.
<html><body>
<script src="//cdn.jsdelivr.net/npm/planck@latest/dist/planck-with-testbed.min.js"></script>
<script>
planck.testbed(function(testbed) {
// Your testbed code
});
</script>
</body></html>
Use NPM package in Node.
const planck = require('planck/dist/planck-with-testbed');
planck.testbed(function() {
// ...
});
- Astray 2 (source) by Rye Terrell
- Rope (source) by Fernando Serboncini
- I have to flap by Elias Ku
- Hoverator by Jonathon Vogel
- Totem Destroyer by Emanuele Feronato
- Pancake Tower by Aloysius Kieth
- Acolyte Fight
- Comeback by Romain Clément
- Nitro Clash
- Space Rage 2 by Hendrik Mans
- Air Hockey (source) by Steve Meredith
- Coined (source)
- Zzzone! (source) by Jan Engehausen
- Star Fly by Kal Torak
- Fall / Fill by Jez Swanson
- 1000 Unique Postcards by Andreas Gysin
- Flag in the Wind by Nick Matantsev
- Dynamic Convex Hull by Bo Zheng
- Chaotic Water Wheel by John Hearn
- Handle by Ichiro Maruta
- Q-Learning Ragdoll by Mikko Kämäräinen
- Walking EA by Mats Krüger Svensson
- Neuroevolution Bots by Mishig Davaadorj
- Bubble Treemaps
- Walking Robot Source
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.
TypeScript definitions for planck.js are developed by Oliver Zell.
Planck.js is available under the MIT license.