Softwave Posted August 20, 2014 Share Posted August 20, 2014 How would I add animations to a class I've extended from sprite? I'm trying to follow the information Extending Sprite Demos 1 and 2 but neither animate the sprites and if I add 'this.animations.add' in the update function I get the error 'animations is not defined'.The code to my class is here: Puppy = function(thisGame,x,y) { Phaser.Sprite.call(this,thisGame,x,y,'puppy');};Puppy.prototype = Object.create(Phaser.Sprite.prototype);Puppy.prototype.constructor = Puppy; Puppy.prototype.create = function() { this.animations.add('idleleft',[0,1,2],4,true); this.animations.add('idleright',[3,4,5],4,true); this.animations.play('idleright');};puppy = new Puppy(this,100,256);this.add.existing(puppy);Other than animations it seems to work. Any help would be greatly appreciated. Link to comment Share on other sites More sharing options...
Softwave Posted August 20, 2014 Author Share Posted August 20, 2014 I fixed the issue by putting the animation adding in the constructor function and by passing this.game instead of this to the class. Tilde 1 Link to comment Share on other sites More sharing options...
Recommended Posts