Vaughan Posted January 31, 2014 Share Posted January 31, 2014 I'm using "Simple Inheritance": http://ejohn.org/blog/simple-javascript-inheritance/Maybe I shouldn't be, and if not I'd like to here some better options. How can I extend a Phaser sprite using this? It does not implement the extend function, which makes interoping with it tricky. I would guess I can do something along the lines of over-riding the Phaser.Sprite.Prototype and constructor, and then trying to 'extend' it after. However, I'm not sure if that's going to have zero side-effects or even work. Link to comment Share on other sites More sharing options...
Vidsneezes Posted January 31, 2014 Share Posted January 31, 2014 I extend my sprites using the example in the examples folder, here .Hope it helps. Link to comment Share on other sites More sharing options...
Vaughan Posted January 31, 2014 Author Share Posted January 31, 2014 I've tried that, but i need to support the extend method: Currently, I have: Entity.prototype = Object.create(Phaser.Sprite.prototype);Entity.prototype.constructor = Entity;Phaser.Sprite.prototype.extend = Class.extend;var Entity = Phaser.Sprite.extend({ init: function(game, x, y, key, frame) { this.game = game; this.id = null; // This is the network ID of the object on the server // Call the phaser sprite chain all the way down this.Sprite(game, x, y, key, frame); },However, I'm being told that 'extend' is not a function on Phaser.Sprite. Which of course, seems to be the case. I need to support this as everywhere elses uses this type of inheritance and it'd look a bit goofy for my entities to break the chain.. Link to comment Share on other sites More sharing options...
Vidsneezes Posted January 31, 2014 Share Posted January 31, 2014 Ah ok. "Simple inheritance" looks pretty neat. reminds me of java.I think, to use Class.extend you need to started out with something like this:Phaser.Sprite = Class.extend({init:function(){//all the stuff}}); to then be able to do something like this:var Entity = Phaser.Sprite.extend({init:function(){this._super();//other stuff}}); (I think )if you want to use Class.extend, i would do something like:Entity = Class.extend({ init: function(game){ Phaser.Sprite.call(this,game,x,y,key,frame); }});then you can create your entities like this:Car = Entity.extend({ init: function(game){ this._super(this,game,x,y,key,frame); }});( i haven't tested this and i feel like i missed something)Anways i was checking the Phaser source and saw an extend method in the Utils.js here. Link to comment Share on other sites More sharing options...
Recommended Posts