charlie_says Posted July 10, 2014 Share Posted July 10, 2014 So, whilst I can see my inherited functions, I don't seem to be able to access variables set in the parent constructor:BaseSprite = function (game){ // create empty sprite Phaser.Sprite.call(this, game); this.arbitraryValue = "hello";};BaseSprite.prototype = Object.create(Phaser.Sprite.prototype);BaseSprite.prototype.constructor = BaseSprite;BaseSprite.prototype.update = function() { };Monster = function (game){ console.log(this.arbitraryValue);; returns};Monster.prototype = Object.create(BaseSprite.prototype);Monster.prototype.constructor = Monster;Monster.prototype.update = function() { }; Link to comment Share on other sites More sharing options...
XekeDeath Posted July 10, 2014 Share Posted July 10, 2014 Because you are not calling the parent constructor...? charlie_says 1 Link to comment Share on other sites More sharing options...
charlie_says Posted July 10, 2014 Author Share Posted July 10, 2014 Apologies for answering my own question.The reason this doesn't work properly is because the child doesn't call the super class constructorMonster = function (game){ BaseSprite.call(this, game); console.log(this.arbitraryValue);} Link to comment Share on other sites More sharing options...
charlie_says Posted July 10, 2014 Author Share Posted July 10, 2014 Thanks XekeDeath - I just realised my mistake, both posting at the same time. Link to comment Share on other sites More sharing options...
Recommended Posts