Jump to content

Sprite inheritance problem

Elad Sofer

Recommended Posts



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 examples
BasicGame.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.


  1. BasicGame.Lizard- lizard.js:4 - (Phaser.Sprite.call(this,game, 110, 350, 'lizard') ;)



Thanks in advance for any help,


Link to comment
Share on other sites

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() {



Link to comment
Share on other sites

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...