Getting Uncaught TypeError: Cannot read property 'index' of undefined on phaser animation

Recommended Posts

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:'left');

Im not sure what is going wrong with it

Heres my player sprite part of my create function:

this.cursors =;

this.player =, 10, 'player');;

//the camera will follow the player in the world;

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;'left');
else if (this.cursors.right.isDown)
    //  Move to the right
    this.player.body.velocity.x = 150;'right');
    //  Stand still

    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;


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.