Jump to content

Noob question. Best practice to store objects?


c75
 Share

Recommended Posts

Hello guys, I started learning phaser not so long ago. And i have a question. Is it ok that the gameObject is a displayObject??

Or may be better to store displayObject as property of gameObject?? (I did so when develope using only pixi)

If I can use it as displayObject as property of gameObject, what about phaser "groups"? Will I've got any problems using gameObject  as displayObject in large projects??

What do you guys think about this aspect?

Link to comment
Share on other sites

I don't think I understand your question.

 

Ok, i give two variants of code. What will you choose??

First. gameObject is displayObject

class Animal extends Phaser.Sprite {    constructor(game, x, y, key, frame) {        super(game, x, y, key, frame);        this.game.stage.addChild(this);        this._someProperty = null;    }    setSomeProperty(someProperty){        this._someProperty = someProperty;    }}

and second gameObject contain displayObject as property

class Animal {    constructor(game, x, y, key, frame) {        this.game = game;        this.x = x;        this.y = y;        this.key = key;        this.frame = frame;        this._someProperty = null;        this.displayObject = {};        this._initDisplay();    }    _initDisplay(){        this.displayObject = new Phaser.Sprite(this.game, this.x, this.y, this.key, this.frame);        this.game.stage.addChild(this.displayObject);    }    setSomeProperty(someProperty){        this._someProperty = someProperty;    }}
Link to comment
Share on other sites

@drhayes, ty for sharing sources of your game. It's great! I've got some fresh ideas :)

And i have another question - is it often a situation when your property coincide with  the inherited class'es properties or methods?  Started reading Interpase#1 and all unclear moments was solved in my head :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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