Skip to content

About

👾 2D arcade physics for JavaScript games, extracted from Phaser's Arcade Physics. Runs without Phaser, with AABB and circle bodies, collisions, overlaps, and tilemaps. MIT licensed.

Resources

Stars

60 stars

Watchers

5 watching

Forks

Latest commit

 

History

48 Commits

Folders and files

Repository files navigation

Arcade Physics
(without Phaser)

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, and overlapBodyVsTiles
  • DebugGraphics for 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-physics

Usage

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.js

Plain 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 test

License

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.js is a fork of this code.

See the LICENSE file for more details.

About

👾 2D arcade physics for JavaScript games, extracted from Phaser's Arcade Physics. Runs without Phaser, with AABB and circle bodies, collisions, overlaps, and tilemaps. MIT licensed.

Resources

Stars

60 stars

Watchers

5 watching

Forks

Used by

Contributors

Languages