Jump to content

Weird Error when loading Animations


Ahmed Khalifa
 Share

Recommended Posts

Hello,

I am still new to HTML5 and Phaser development. I was trying to add animations to a sprite but it always through this error

Uncaught TypeError: Cannot read property 'add' of undefined

in the phaser.js file at that line:

this.game.onPause.add(this.onPause, this);

here is my code:

Player = function(game, xIn, yIn, key){	Phaser.Sprite.call(this, game, xIn, yIn, key);	this.texture.baseTexture.scaleMode = PIXI.scaleModes.NEAREST;	this.animations.add(PlayerState.STANDING + Direction.LEFT, [4], 0, false);	this.animations.add(PlayerState.STANDING + Direction.RIGHT, [0], 0, false);	this.animations.add(PlayerState.STANDING + Direction.UP, [8], 0, false);	this.animations.add(PlayerState.STANDING + Direction.DOWN, [12], 0, false);	this.playerState = PlayerState.STANDING;	this.direction = Direction.LEFT;	this.weapon = null;};Player.prototype = Object.create(Phaser.Sprite.prototype);Player.prototype.constructor = Player;Player.prototype.update = function(){	if(this.game.input.keyboard.isDown(Phaser.Keyboard.LEFT)){		this.direction = Direction.LEFT;	}	if(this.game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)){		this.direction = Direction.RIGHT;	}	if(this.game.input.keyboard.isDown(Phaser.Keyboard.UP)){		this.direction = Direction.UP;	}	if(this.game.input.keyboard.isDown(Phaser.Keyboard.DOWN)){		this.direction = Direction.DOWN;	}	this.animations.play(this.playerState + this.direction);};Player.prototype.shoot = function(direction){	console.log('Shoot: ' + direction);};

and the loading of the texture and construction is in the GameState class.

 

Sorry for my stupidity and thanks in advance :)

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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