NickCastello Posted March 14, 2017 Report Share Posted March 14, 2017 down votefavorite I keep having a problem with animations in my code. I try playing an animation and i always get the same message: "Uncaught TypeError: Cannot read property 'index' of undefined" and it always points to the same line of my code which is: this.player.animations.play('left'); Im not sure what is going wrong with it Heres my player sprite part of my create function: this.cursors = this.game.input.keyboard.createCursorKeys(); this.player = this.game.add.sprite(10, 10, 'player'); this.game.physics.arcade.enable(this.player); this.player.scale.setTo(.4,.4); //the camera will follow the player in the world this.game.camera.follow(this.player); this.player.animations.add('left', [0, 1, 2, 3, 4, 5, 6], 10, true, false); this.player.animations.add('right', [11, 12, 13, 14, 15, 16, 17], 10, true, false); My temporary update function: update: function() { if (this.cursors.left.isDown) { // Move to the left this.player.body.velocity.x = -150; this.player.animations.play('left'); } else if (this.cursors.right.isDown) { // Move to the right this.player.body.velocity.x = 150; this.player.animations.play('right'); } else { // Stand still this.player.animations.stop(); this.player.frame = 4; } // Allow the player to jump if they are touching the ground. if (this.cursors.up.isDown && player.body.touching.down) { this.player.body.velocity.y = -350; } } Quote Link to comment Share on other sites More sharing options...
PhaserEditor2D Posted March 14, 2017 Report Share Posted March 14, 2017 Are you loading the 'player' asset as spritesheet or image? samme 1 Quote Link to comment Share on other sites More sharing options...
samme Posted March 14, 2017 Report Share Posted March 14, 2017 Try console.log(this.player.getAnimation('left')._anims) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.