Arcade Physics
on Node.js and Bun
The same code runs on Node.js and Bun without a browser. The window below runs this script in your browser and prints its output to the terminal underneath.
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
const timer = setInterval(() => {
physics.world.update(tick * 1000, 1000 / 60)
physics.world.postUpdate()
tick++
if (tick % 30 === 0) {
console.log(`tick ${tick}: box x=${box.x.toFixed(1)} y=${box.y.toFixed(1)}`)
}
if (tick === 240) {
clearInterval(timer)
console.log('done')
}
}, 16)
$ node index.mjs
Output from a browser run. Node.js 22 and Bun 1.2 print the same lines.