Loading...
Loading...
Use Phaser 3 Arcade Physics: enable the world, give sprites bodies, set velocity/acceleration/gravity, and resolve collisions with colliders, overlaps, groups, and world bounds. Use when a Phaser game needs movement or collisions — when the user mentions Arcade Physics, this.physics, setVelocity, collider, overlap, gravity, onFloor, or a platformer/top-down controller. For game config, scenes, and the loader use phaser-core.
npx skill4agent add gamedev-skills/awesome-gamedev-agent-skills phaser-arcade-physicsphysics: { default: 'arcade' }this.physics.add.*body.setVelocitythis.physics.add.colliderGamephaser-corephysics-tuningphysics: { default: 'arcade', arcade: { gravity: {...}, debug: true } }debugthis.physics.add.sprite(...)this.physics.add.staticImage(...)this.physics.add.existing(obj)xysetVelocitysetAccelerationsetBouncesetCollideWorldBoundsthis.physics.add.collider(a, b)this.physics.add.overlap(a, b, cb)this.physics.add.group()staticGroup()body.onFloor()body.blocked.downdebug: trueconst config = {
type: Phaser.AUTO,
width: 800, height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { x: 0, y: 600 }, // top-down? use { x: 0, y: 0 }
debug: false // true to draw bodies + velocity while building
}
},
scene: [PlayScene]
};
new Phaser.Game(config);create() {
this.player = this.physics.add.sprite(400, 300, 'player');
this.player.setCollideWorldBounds(true);
this.cursors = this.input.keyboard.createCursorKeys();
}
update() {
const speed = 220;
const body = this.player.body;
body.setVelocity(0); // reset each frame
if (this.cursors.left.isDown) body.setVelocityX(-speed);
if (this.cursors.right.isDown) body.setVelocityX(speed);
if (this.cursors.up.isDown) body.setVelocityY(-speed);
if (this.cursors.down.isDown) body.setVelocityY(speed);
body.velocity.normalize().scale(speed); // keep diagonals same speed
}create() {
this.player = this.physics.add.sprite(100, 450, 'player');
this.player.setCollideWorldBounds(true);
// Static platforms: one body each, never moved by collisions.
this.platforms = this.physics.add.staticGroup();
this.platforms.create(400, 568, 'ground');
this.physics.add.collider(this.player, this.platforms);
this.cursors = this.input.keyboard.createCursorKeys();
}
update() {
const onGround = this.player.body.blocked.down; // or this.player.body.onFloor()
if (this.cursors.left.isDown) this.player.setVelocityX(-160);
else if (this.cursors.right.isDown) this.player.setVelocityX(160);
else this.player.setVelocityX(0);
if (this.cursors.up.isDown && onGround) this.player.setVelocityY(-450);
}// Push apart and react: player vs enemies.
this.physics.add.collider(this.player, this.enemies, (player, enemy) => {
this.handleHit(player, enemy);
});
// Detect without pushing: collect coins. The 4th arg is an optional
// process callback returning a boolean to filter pairs before the main callback.
this.physics.add.overlap(this.player, this.coins, (player, coin) => {
coin.disableBody(true, true); // deactivate + hide
this.registry.inc('score', 10);
});this.bullets = this.physics.add.group({
defaultKey: 'bullet',
maxSize: 30 // pool size; reuse instead of allocating
});
fire(x, y) {
const bullet = this.bullets.get(x, y); // reuses a dead bullet if available
if (!bullet) return;
bullet.enableBody(true, x, y, true, true);
bullet.setVelocityY(-500);
}this.add.spritethis.physics.add.spritethis.physics.add.existing(obj)sprite.xsetVelocitysetAccelerationstaticGroupbody.setImmovable(true)onFloor()colliderbody.updateFromGameObject()refreshBody()collideroverlapcreateupdatesetSizesetCirclesetOffsetworldboundsreferences/bodies-and-collision.mdphaser-corephysics-tuningplatformertower-defenselevel-design