c75 Posted January 8, 2016 Share Posted January 8, 2016 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 More sharing options...
c75 Posted January 8, 2016 Author Share Posted January 8, 2016 Here it is my variance of storing displayObject as property of gameObject. https://github.com/avin/animal-discover-demo Link to comment Share on other sites More sharing options...
drhayes Posted January 8, 2016 Share Posted January 8, 2016 I don't think I understand your question. Yes, I store things on the game instance all the time: the player, plugins, etc. Link to comment Share on other sites More sharing options...
c75 Posted January 8, 2016 Author Share Posted January 8, 2016 I don't think I understand your question. Ok, i give two variants of code. What will you choose??First. gameObject is displayObjectclass 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 propertyclass 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 More sharing options...
drhayes Posted January 8, 2016 Share Posted January 8, 2016 Oh! Okay. I do the first one all the time: here's the player from a game I made recently. c75 1 Link to comment Share on other sites More sharing options...
c75 Posted January 9, 2016 Author Share Posted January 9, 2016 @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 drhayes 1 Link to comment Share on other sites More sharing options...
drhayes Posted January 10, 2016 Share Posted January 10, 2016 Good deal! Happy to help... and welcome aboard! Link to comment Share on other sites More sharing options...
Recommended Posts