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, config.height, "ground");
this.platforms.create(config.width / 2, config.height / 2, "ground");
this.platforms.create(config.width / 4, config.height / 1.33, "ground");
this.platforms.create(config.width / 1.33, config.height / 1.33, "ground");
this.platforms.children.iterate((platform) => {
platform.body.checkCollision.up = true;
platform.body.checkCollision.down = false;
platform.body.checkCollision.right = false;
platform.body.checkCollision.left = false;
this.player = this.physics.add.sprite(config.width / 2, 0, "dude");
this.player.setBounce(0);
this.player.setSize(16, 46);
this.player.setOffset(32, 18);
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.playerCollider = this.physics.add.collider(
this.cursors = this.input.keyboard.addKeys({
down: Phaser.Input.Keyboard.KeyCodes.S,
left: Phaser.Input.Keyboard.KeyCodes.A,
right: Phaser.Input.Keyboard.KeyCodes.D,
jump: Phaser.Input.Keyboard.KeyCodes.SPACE
if (this.cursors.left.isDown) {
this.player.setVelocityX(-160);
this.player.anims.play("walk", true);
this.player.flipX = false;
} else if (this.cursors.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.cursors.jump.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);
this.cursors.down.isDown &&
this.cursors.jump.isDown &&
this.player.body.touching.down
this.playerCollider.active = false;
this.player.setVelocityY(300);
this.playerCollider.active = true;
if (this.player.y > config.height + this.player.height) {
this.player.setPosition(config.width / 2, 0);
const game = new Phaser.Game(config);
activateControls(["A", "S", "D", "space"]);