arcade-physics
v0.2.1
Published
Standalone 2D Arcade Physics for JavaScript games, based on Phaser's Arcade Physics. Supports AABB and circle bodies, collisions, overlaps, and tilemaps.
Maintainers
Readme
2D arcade physics for JavaScript games, extracted from the Arcade Physics module of Phaser. It runs without the Phaser game framework.
It runs in browsers, on Node.js (tested with 22), and on Bun (tested with 1.2).
Goal
Detach Arcade Physics from the Phaser package so it can be used on its own in any JavaScript game or canvas project.
Features
- AABB and circle bodies, static bodies, gravity, bounce, friction, and world bounds
- Collisions and overlaps between bodies
- Tilemap collisions with
createTilesFromGrid,collideBodyVsTiles, andoverlapBodyVsTiles DebugGraphicsfor drawing body outlines- Group support has been removed. Use a plain array instead of a Group.
Demo (client-side)
https://yandeu.github.io/arcade-physics/
Also available on html2app: https://html2app.dev/tools/arcade-physics
The demo pages are in demo/: index.html, tilemap.html, and server.html, which shows a Node.js and Bun script with its console output.
NPM
npm i arcade-physicsUsage
import { LoadArcadePhysics } from "arcade-physics";
const physics = await LoadArcadePhysics({
width: 800,
height: 450,
gravity: { x: 0, y: 300 },
});
const box = physics.add.body(20, 20, 64, 64);
box.setBounce(0.6);
box.setCollideWorldBounds(true);
const platform = physics.add.staticBody(60, 350, 160, 32);
physics.add.collider(box, platform);
let tick = 0;
setInterval(() => {
physics.world.update(tick * 1000, 1000 / 60);
physics.world.postUpdate();
tick++;
}, 16);For a complete example, see the config and setup in demo/index.html.
Bundles (without npm)
If your page is not built with a bundler, use one of the prebuilt bundles. Each bundle contains the whole library, including Phaser's physics code.
| File | Format | Use it with |
| ----------------------------------- | ------ | ---------------------------------------------- |
| bundles/arcade-physics.esm.min.js | ESM | <script type="module"> |
| bundles/arcade-physics.umd.min.js | UMD | <script>, exposes the global ArcadePhysics |
The bundles do not include TypeScript declarations. Use the npm package for types.
Download a bundle into the same folder as your HTML page:
curl -O https://unpkg.com/arcade-physics/bundles/arcade-physics.umd.min.jsPlain HTML with the UMD bundle
<!DOCTYPE html>
<html>
<body>
<script src="arcade-physics.umd.min.js"></script>
<script>
ArcadePhysics.LoadArcadePhysics({
width: 800,
height: 450,
gravity: { x: 0, y: 300 },
}).then((physics) => {
const box = physics.add.body(20, 20, 64, 64);
console.log("box", box.x, box.y);
});
</script>
</body>
</html>Plain HTML with the ESM bundle
index.html:
<!DOCTYPE html>
<html lang="en">
<body>
<script type="module" src="app.js"></script>
</body>
</html>app.js (same folder, next to arcade-physics.esm.min.js):
import { LoadArcadePhysics } from "./arcade-physics.esm.min.js";
const physics = await LoadArcadePhysics({
width: 800,
height: 450,
gravity: { x: 0, y: 300 },
});
const box = physics.add.body(20, 20, 64, 64);
console.log("box", box.x, box.y);The ESM bundle must be served over HTTP(S), because browsers block module scripts loaded from file://. The UMD bundle works when you open the HTML file directly.
Development
git clone https://github.com/yandeu/arcade-physics.git
cd arcade-physics
npm run init # fetches the pinned Phaser source into src/phaser
npm install
npm run build # writes dist/ (npm entry and types), dist/arcade-physics.min.js, and bundles/
npm testLicense
MIT License. Copyright (c) 2026 Yannick Deubel
This project includes code from third-party MIT licensed projects. Their copyright notices and license texts are included in the banner at the top of dist/index.js. The type definitions in dist/phaser.d.ts and dist/matter.d.ts start with Phaser's license notice.
- Phaser, Copyright (c) 2013-2026 Richard Davey, Phaser Studio Inc.
- eventemitter3, Copyright (c) 2014 Arnout Kazemier
- rbush, Copyright (c) 2024 Volodymyr Agafonkin. Phaser's
RTree.jsis a fork of this code.
See the LICENSE file for more details.
