Hi everyone, I’m new on forum.
I am currently trying to make a game with Phaser3 and I am following an online tutorial (Zenva academy). The guy in the video does not get this error even though we have the same code. He uses Phaser v3.16.2 and I use Phaser v3.24.1. The console shows me:
Uncaught TypeError: scene.sys is undefined phaser.js:3022:9
Here is my code from main.js:
var config = { type: Phaser.AUTO, width: 800, height: 600, scene: [ BootScene, TitleScene, GameScene, UiScene ], physics: { default: 'arcade', arcade: { debug: true, gravity: { y: 5 } } } }; var game = new Phaser.Game(config);
BootScene.js:
class BootScene extends Phaser.Scene {
constructor() {
super(‘Boot’);
}preload() { this.load.image('button1', 'assets/images/ui/blue_button01.png'); this.load.spritesheet('items', 'assets/images/items.png', { frameWidth: 32, frameHeight: 32 }); this.load.spritesheet('characters', 'assets/images/characters.png', { frameWidth: 32, frameHeight: 32 }); this.load.audio('goldSound', ['assets/audio/Pickup.wav']); } create() { this.scene.start('Game'); }
}
Player.js:
class Player extends Phaser.Physics.Arcade.Image {
constructor(scene, x, y, key, frame) {
super(scene, x, y, key, frame);
this.scene = scene;
this.velocity = 160;this.scene.physics.world.enable(this); this.setImmovable(false); this.setScale(2); this.setCollideWorldBounds(true); scene.add.existing(this); } update(cursors) { this.body.setVelocity(0); if (cursors.left.isDown) { this.body.setVelocityX(-this.velocity); } else if (cursors.right.isDown) { this.body.setVelocityX(this.velocity); } if (cursors.up.isDown) { this.body.setVelocityY(-this.velocity) } else if (cursors.down.isDown) { this.body.setVelocityY(this.velocity) } }
}
GameScene.js:
class GameScene extends Phaser.Scene {
constructor() {
super(‘Game’);
}create() { var goldPickupAudio = this.sound.add('goldSound', { loop: false, volume: 0.2 }); var button = this.add.image(100, 100, 'button1'); button.setOrigin(0.5, 0.5); this.add.sprite(300, 100, 'button1'); this.chest = this.physics.add.image(300, 300, 'items', 0); this.wall = this.physics.add.image(500, 100, 'button1'); this.wall.setImmovable(); this.player = new Player(32, 32, 'characters', 0); this.physics.add.collider(this.player, this.wall); this.physics.add.overlap(this.player, this.chest, function (player, chest) { goldPickupAudio.play(); chest.destroy(); }); this.cursors = this.input.keyboard.createCursorKeys(); } update() { this.player.update(this.cursors); }
}
What is it that causes this error? What am I doing wrong?