notalentgeek Posted January 7, 2015 Share Posted January 7, 2015 Hello there! I am just started using Phaser like a month ago. Before using Phaser, I used Flixel or GameMaker. For every tutorial I have followed, no one mentioned about inheritance in Phaser. Is there a way how to do inherintance/parenting in Phaser? Link to comment Share on other sites More sharing options...
Massemassimo Posted January 7, 2015 Share Posted January 7, 2015 Maybe I am an idiot but isn't inheritance a feature of Typescript / vanilla javascript, not Phaser? Link to comment Share on other sites More sharing options...
ericjbasti Posted January 7, 2015 Share Posted January 7, 2015 Inheritance is a feature of Javascript. So its hard to make anything that doesn't support it (probably impossible). Without knowing too much about how Phaser is suppose to work I can tell you that it uses Inheritance all over the place. You can inherit from it as well. If you wanted to create a new type of Sprite for example you would do something like this :var MySpriteType = function(attr){ this.x = 500; this.y = 200;}MySpriteType.prototype = Object.create(Phaser.Sprite.prototype);MySpriteType.constructor = MySpriteType;I based my pattern on what Phaser is doing, since it inherits a lot from Pixi.js This is how Phaser extends/inherits Pixi's Sprite type/class:Phaser.Sprite = function (game, x, y, key, frame) { x = x || 0; y = y || 0; //... a bunch of other code ...}Phaser.Sprite.prototype = Object.create(PIXI.Sprite.prototype);Phaser.Sprite.prototype.constructor = Phaser.Sprite; Link to comment Share on other sites More sharing options...
Recommended Posts