Jump to content

Can't add image in non Scene class


KungFuFlames
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...