Pham Duc Truc Posted September 11, 2014 Share Posted September 11, 2014 I using Extending Sprite for my game FishSprite.js: FishSprite = function (game, x,y,key) { Phaser.Sprite.call(this, game, x, y, key); this.anchor.setTo(0.5, 0.5); game.add.existing(this);}; 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 errorthis.s_fish1.animations.add('s_fish1boi', [0,1,2,3], 10, true); // error herethis.s_fish1.animations.play('s_fish1boi'); Pls help me!my src in attach files Fish.zip Link to comment Share on other sites More sharing options...
JUL Posted September 11, 2014 Share Posted September 11, 2014 http://examples.phaser.io/_site/view_full.html?d=animation&f=sprite+sheet.js&t=sprite%20sheetProof of concept. That's the reliable way to do it. Link to comment Share on other sites More sharing options...
lewster32 Posted September 11, 2014 Share Posted September 11, 2014 Try this:this.s_fish1 = new FishSprite(this.game,50,400,'fish1');You need to pass the game instance to the Sprite object and anything that extends it. Pham Duc Truc 1 Link to comment Share on other sites More sharing options...
Pham Duc Truc Posted September 12, 2014 Author Share Posted September 12, 2014 Thank you very much! I im newbie. I don't know where "this.game" is define. I think in BasicGame.Game "this" mean game Link to comment Share on other sites More sharing options...
lewster32 Posted September 12, 2014 Share Posted September 12, 2014 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 More sharing options...
Recommended Posts