Elad Sofer Posted April 29, 2014 Share Posted April 29, 2014 Hi, I have looked at the examples and i guess i am missing something... i am adding as much info as i have even most of it is probably irrelevant. Sorry for that, I have the BasicGame class which has 4 states in different files (as shown in example): game.state.add('Boot', BasicGame.Boot);game.state.add('Preloader', BasicGame.Preloader);game.state.add('MainMenu', BasicGame.MainMenu);game.state.add('Game', BasicGame.Game);I have also created a new class called BasicGame.Lizard which inherits from sprite exactly as explained in the examplesBasicGame.Lizard= function (game) { Phaser.Sprite.call(this,game, 110, 350, 'lizard');};BasicGame.Lizard.prototype = Object.create(Phaser.Sprite.prototype);BasicGame.Lizard.prototype.constructor = BasicGame.Lizard;BasicGame.Lizard.prototype = { .... }On the create function in BasicGame.Game i try to create a new Lizard :this.lizard = new BasicGame.Lizard(this);And get an "Uncaught TypeError: undefined is not a function " which is coming from this call stack. PIXI.Sprite - phaser.js:1714 - (this.onTextureUpdate() Phaser.Sprite- phaser.js:26375 - (PIXI.Sprite.call(this, PIXI.TextureCache['__default']) BasicGame.Lizard- lizard.js:4 - (Phaser.Sprite.call(this,game, 110, 350, 'lizard') Thanks in advance for any help,Elad. Link to comment Share on other sites More sharing options...
ctmartinez1992 Posted April 29, 2014 Share Posted April 29, 2014 I'm not sure if the way you did is an alternative to what i do but, to add a sprite i do like thus:game.add.sprite(110, 350, 'lizard');The way you're doing might work but i have never seen anyone do it like that. Link to comment Share on other sites More sharing options...
Dream Of Sleeping Posted April 29, 2014 Share Posted April 29, 2014 BasicGame.Lizard.prototype = { .... } // remove this Javascript inherritence is confusing so I may be wrong but I think that's the problem. You had set it's prototype to be a sprite, but then you just changed it. If you want to add new functions to your Lizard object do this. BasicGame.Lizard.prototype.anotherFunction = function() { } Elad Sofer 1 Link to comment Share on other sites More sharing options...
ctmartinez1992 Posted April 29, 2014 Share Posted April 29, 2014 Oh, he actually has that in the code? I assumed it was to show that the rest of the code was irrelevant Link to comment Share on other sites More sharing options...
Dream Of Sleeping Posted April 29, 2014 Share Posted April 29, 2014 Well I assumed the prototype contains stuff and I realize that the {... } was to show that it's not important. But I thought if you were to create a prototype like that (including new variables and stuff) it would replace sprite as the prototype, therefore undoing the inherritence. But I totally could be wrong. Link to comment Share on other sites More sharing options...
Dream Of Sleeping Posted April 29, 2014 Share Posted April 29, 2014 Also here. this.lizard = new BasicGame.Lizard(this); What is 'this' you are passing it. Is it the state? Because you need to pass it the game instance. You sould try this this.lizard = new BasicGame.Lizard(this.game) Link to comment Share on other sites More sharing options...
ctmartinez1992 Posted April 29, 2014 Share Posted April 29, 2014 Or you're correct and i'm a dumbass because i forgot that he is doing inheritance Carry on... Dream Of Sleeping 1 Link to comment Share on other sites More sharing options...
Elad Sofer Posted April 29, 2014 Author Share Posted April 29, 2014 Dream of Sleeping thanks a lot! The issue was with the way i implemented the inheritance. Link to comment Share on other sites More sharing options...
Recommended Posts