class Example extends Phaser.Scene {
this.load.image("bg", "https://assets.codepen.io/9367036/bg2.png");
this.cursors = this.input.keyboard.createCursorKeys();
const hw = config.width / 2;
const hh = config.height / 2;
this.positionText = this.add
let img = this.add.image(hw, hh, "bg").setOrigin(0.5, 0.5);
let scaleX = config.width / img.width;
let scaleY = config.height / img.height;
let scale = Math.max(scaleX, scaleY);
this.player = this.add.circle(hw, hh, 10, 0xcccc00);
this.physics.add.existing(this.player);
this.player.body.setCollideWorldBounds();
.rectangle(222, 195, 45, 160, 0xff0000)
this.physics.add.existing(this.obstacle);
this.obstacle.body.setImmovable();
this.physics.add.collider(this.player, this.obstacle);
if (this.cursors.left.isDown) {
this.player.body.setVelocityX(-this.speed);
} else if (this.cursors.right.isDown) {
this.player.body.setVelocityX(this.speed);
this.player.body.setVelocityX(0);
if (this.cursors.up.isDown) {
this.player.body.setVelocityY(-this.speed);
} else if (this.cursors.down.isDown) {
this.player.body.setVelocityY(this.speed);
this.player.body.setVelocityY(0);
this.positionText.setText(
parseInt(this.player.x) +
parseInt(this.player.y) +
const game = new Phaser.Game(config);
activateControls(["left", "right", "up", "down"]);