class ExampleScene extends Phaser.Scene {
ball;
paddle;
// ...
}Player paddle and controls / notebook
Player paddle and controls
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
class ExampleScene extends Phaser.Scene {
// ...
preload() {
this.load.image("ball", "img/ball.png");
this.load.image("paddle", "img/paddle.png");
}
// ...
}this.paddle = this.add.sprite(
this.scale.width * 0.5,
this.scale.height - 5,
"paddle",
);this.paddle.setOrigin(0.5, 1);this.physics.add.existing(this.paddle);class ExampleScene extends Phaser.Scene {
// ...
update() {
this.physics.collide(this.ball, this.paddle);
}
}this.paddle.body.setImmovable(true);this.ball.body.setBounce(1);this.paddle.x = this.input.x;this.paddle.x = this.input.x || this.scale.width * 0.5;this.ball = this.add.sprite(
this.scale.width * 0.5,
this.scale.height - 25,
"ball",
);this.ball.body.setVelocity(150, -150);