
used version: 3.10.1
And the code that caused this is .... ?
No example provided so closing this issue.
I've got this error when I've instantiated a Phaser.GameObjects.Sprite class inside a Phaser.Scene direct in the constructor. It meant to be done inside create method.
If you're playing with TypeScript, don't forget to mark the property with the ! (bang) operator, otherwise you will get the following error: Property 'YOUR PROPERTY' has no initializer and is not definitely assigned in the constructor.
Cheers
I also saw this error when creating a class that inherited from a base class, and the one inheriting was redefining scene like:
// GameScene.js
import Goon from '../sprites/Goon';
class GameScene extends Phaser.Scene {
constructor(test) {
super({
key: 'GameScene'
});
this.cursors;
this.goon;
}
preload() {
this.goon = new Goon({
scene: this,
x: this.sys.game.config.width / 2,
y: this.sys.game.config.height / 2,
key: 'person'
});
}
....etc...
// Goon.js
import Enemy from './Enemy.js';
export default class Goon extends Enemy {
constructor(config) {
super(config);
config.scene = scene; // <--- DO NOT DO THIS
this.body.setVelocity(0, 0).setBounce(0.2).setCollideWorldBounds(true);
}
preload() {}
create() {}
update() {}
destroy() {}
}
// Enemy.js
export default class Enemy extends Phaser.GameObjects.Sprite {
constructor(config) {
super(config.scene, config.x, config.y, config.key);
config.scene.physics.world.enable(this);
config.scene.add.existing(this);
this.body.setVelocity(0, 0).setBounce(0.2).setCollideWorldBounds(true);
}
}
@bpkennedy I have encountered the same problem as you did when extend the class extends Phaser.GameObjects.Sprite
Most helpful comment
I've got this error when I've instantiated a
Phaser.GameObjects.Spriteclass inside aPhaser.Scenedirect in the constructor. It meant to be done insidecreatemethod.If you're playing with TypeScript, don't forget to mark the property with the
!(bang) operator, otherwise you will get the following error:Property 'YOUR PROPERTY' has no initializer and is not definitely assigned in the constructor.Cheers