KungFuFlames Posted April 15, 2018 Share Posted April 15, 2018 Hey there guys! I working on first MVC project with Phaser 3(3.4.0) with Typescript export class Game extends Phaser.Scene { constructor() { super({ key: GAME_SCENE_KEY }); } create() { console.log('This is game scene'); this.add.image(500, 300, BLACK_CELL_IMAGE_KEY); this.add.image(564, 300, WHITE_CELL_IMAGE_KEY); this.add.image(500, 364, WHITE_CELL_IMAGE_KEY); this.add.image(564, 364, BLACK_CELL_IMAGE_KEY); } } So this code fragment works perfectly. But when I try to add a image in non Scene class it doesn't work. export abstract class UIElement{ game: Phaser.Game; cellSprite: Phaser.GameObjects.Image; position: Phaser.Geom.Point; constructor(game: Phaser.Game, rowPos: number, columnPos: number) { this.game = game; this.position = new Phaser.Geom.Point(rowPos, columnPos); this.add.image(this.position.x, this.position.y); } } This is a part of the View that I'm working for the MVC but I can't really get away from this. this.add.image(this.position.x, this.position.y); Any ideas? Link to comment Share on other sites More sharing options...
rich Posted April 15, 2018 Share Posted April 15, 2018 ‘this.add’ is a reference to the Game Object Factory plugin installed in the Scene. I would pass the Scene to your UIElement, not ‘game’ and then you can call ‘add’ on it. Link to comment Share on other sites More sharing options...
KungFuFlames Posted April 15, 2018 Author Share Posted April 15, 2018 Works perfectly! Thanks Link to comment Share on other sites More sharing options...
Recommended Posts