Jump to content

Inherited sprite update not firing


Eli Broide
 Share

Recommended Posts

Hey, I got a class inheriting from sprite.

 

Example

function Player(x, y, options){   Phaser.Sprite.call(this, game, x, y);}Player.prototype = Object.create(Phaser.Sprite.prototype);Player.prototype.constructor = Player;Player.prototype.update = function() {   console.log('here');}

The console shows "here" when I do 

game.add.existing(new Player(0, 0));

However, it does not show "here" when I do

var player = new Player(0,0);var container = game.add.sprite();container.addChild(player);

How can I change it so it would work?

 

Link to comment
Share on other sites

I personally use this way when extending a sprite

function Player(x, y, options){   Phaser.Sprite.call(this, game, x, y);   game.add.existing(this);}

This way, there is no need to call game.add.existing individually on all the extended sprites.

 

In your second method, since the sprite has not been added to the stage, it just sits there doing nothing.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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