rybaqs Posted July 18, 2018 Share Posted July 18, 2018 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). Link to comment Share on other sites More sharing options...
rich Posted July 18, 2018 Share Posted July 18, 2018 The extend approach above will work fine in ES6. Failing that, just declare `player` as a property in your Scene class, not a const in create, which scopes it to that function only. Link to comment Share on other sites More sharing options...
Recommended Posts