class Example extends Phaser.Scene {
super({ key: "Example" });
"https://assets.codepen.io/9367036/Dark_lvl1_selected.png"
"https://assets.codepen.io/9367036/GandalfHardcore+Warrior.png",
this.platforms = this.physics.add.staticGroup();
this.platforms.create(config.width / 2, 380, "ground");
this.platforms.create(600, 300, "ground");
this.platforms.create(50, 250, "ground");
this.platforms.create(750, 200, "ground");
this.player = this.physics.add.sprite(config.width / 2, 200, "dude");
this.player.setSize(16, 46);
this.player.setOffset(32, 18);
this.player.setBounce(0);
this.player.body.setGravityY(1000);
frames: this.anims.generateFrameNumbers("dude", { start: 10, end: 17 }),
frames: this.anims.generateFrameNumbers("dude", { start: 0, end: 4 }),
frames: this.anims.generateFrameNumbers("dude", { start: 40, end: 43 }),
frames: this.anims.generateFrameNumbers("dude", { start: 50, end: 53 }),
this.physics.add.collider(this.player, this.platforms);
this.keys = this.input.keyboard.addKeys({
up: Phaser.Input.Keyboard.KeyCodes.SPACE,
down: Phaser.Input.Keyboard.KeyCodes.S,
left: Phaser.Input.Keyboard.KeyCodes.A,
right: Phaser.Input.Keyboard.KeyCodes.D
if (this.keys.left.isDown) {
this.player.setVelocityX(-160);
this.player.anims.play("walk", true);
this.player.flipX = false;
} else if (this.keys.right.isDown) {
this.player.setVelocityX(160);
this.player.anims.play("walk", true);
this.player.flipX = true;
this.player.setVelocityX(0);
this.player.anims.play("idle", true);
if (this.keys.up.isDown && this.player.body.touching.down) {
this.player.setVelocityY(-500);
if (!this.player.body.touching.down) {
if (this.player.body.velocity.y < 0) {
this.player.anims.play("jump", true);
} else if (this.player.body.velocity.y > 0) {
this.player.anims.play("fall", true);
if (this.player.body.velocity.x !== 0) {
this.player.anims.play("walk", true);
this.player.anims.play("idle", true);
if (this.player.y > config.height + this.player.height) {
this.player.setPosition(450, 200);
const game = new Phaser.Game(config);
activateControls(["space", "A", "D"]);