Jump to content

Extending Sprite animations.add(...) error

Pham Duc Truc

Recommended Posts

I using  Extending Sprite for my game




FishSprite = function (game, x,y,key) {
    Phaser.Sprite.call(this, game, x, y, key);
    this.anchor.setTo(0.5, 0.5);            
FishSprite.prototype = Object.create(Phaser.Sprite.prototype);
FishSprite.prototype.constructor = FishSprite;
FishSprite.prototype.update = function() {
using in Game.js
this.s_fish1 = new FishSprite(this,50,400,'fish1'); // use this will error
this.s_fish1.animations.add('s_fish1boi', [0,1,2,3], 10, true); // error here
Pls help me!
my src in attach files



Link to comment
Share on other sites

No, 'this' in BasicGame.Game refers to the 'Game' state itself, but not the Phaser.Game object. That should always be accessible via this.game in a state. That's why using this.add.sprite works in the previous commented out line in your code, because that function provides new Phaser.Sprite with the correct game reference.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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