KungFuFlames

Can't add image in non Scene class

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.