Corsair Posted April 7, 2018 Share Posted April 7, 2018 How can I access an instance of a class outside the class? class World extends Phaser.Scene { constructor() { super({ key: 'World' }); } preload() { this.load.image('grass','images/world/tiles/grass.png'); } create (){ this.img = this.add.image(100,100,'grass'); this.input.on('pointermove', (pointer) => { this.img.x = pointer.x; this.img.y = pointer.y; }); } } How i can access to 'this.img' outside World class? Link to comment Share on other sites More sharing options...
digitsensitive Posted April 7, 2018 Share Posted April 7, 2018 In Typescript you would define the img outside of the create function and mark it as private and create a getter function. class World extends Phaser.Scene { private img: Phaser.GameObjects.Image; public getImg(): Phaser.GameObjects.Image { return this.img; } } Link to comment Share on other sites More sharing options...
Recommended Posts