I know that this question is really basic one, but I need help with it.
Let's assume, we've got this simple Scene:
class OverworldScene extends Phaser.Scene {
constructor(config) {
super({
key: 'OverworldScene'
});
}
preload() {...}
create() {
const player = this.physics.add.sprite(100, 100, 'tank', 'tank1');
}
update() {
this.cameras.main.scrollX = player.x;
this.cameras.main.scrollY = player.y;
}
}
export default OverworldScene;
This code is not proper, becouse it says player is not available in update() function. How to fix this?
Should I use this.player?
Btw, here's really cool solution, but it's in ES5 https://labs.phaser.io/edit.html?src=src\games\topdownShooter\topdown_averageFocus.js
var config = {
type: Phaser.WEBGL,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 0 },
debug: true
}
},
scene: {
preload: preload,
create: create,
update: update,
extend: {
player: null,
reticle: null,
moveKeys: null,
bullets: null,
lastFired: 0,
time: 0,
}
}
};
this "extend" bit - I would love to use it in ES6 (I've got array of Scenes in this place).