Eli Broide Posted March 30, 2015 Share Posted March 30, 2015 Hey, I got a class inheriting from sprite. Examplefunction 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 dovar 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 More sharing options...
Akshar Patel Posted April 2, 2015 Share Posted April 2, 2015 I personally use this way when extending a spritefunction 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 More sharing options...
Recommended Posts