Jump to content

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


NickCastello
 Share

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:

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;
}

}
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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