Your First Scene
Build and run your first Phaser 4 scene — a bouncing logo — in a sandboxed playground.
A Phaser 4 program is, at minimum, a Game configured with at least one Scene. A scene has three lifecycle hooks you’ll use constantly:
preload()— load assets into the cache.create()— build the initial scene graph.update(time, delta)— run per-frame logic.
Here is the smallest interesting program: a sprite that bounces around its bounds. Edit the source in your own project and the same code will run identically.
What just happened
Phaser.AUTOasks Phaser to pick the best renderer (WebGL where available, Canvas otherwise).- The
physicsconfig enables Arcade physics with no gravity, so the sprite moves in a straight line until something deflects it. this.load.image(key, url)queues an asset; the loader resolves it beforecreate()runs.this.physics.add.image(...)creates a sprite that participates in physics — that’s why it hassetVelocityandsetBounce.setCollideWorldBounds(true)turns the game’s bounding box into a collider, giving us the “bounce” effect.
Where to go next
- Learn the scene lifecycle in detail.
- Understand how game objects are organized.
- Pick a physics system in the physics guide.