Jump to content

Issue with sprite animation


raenset
 Share

Recommended Posts

Hello,

I am doing a simple Platformer game with Phaser, for learning purposes. I have a sprite that is 2 columns x 2 rows (see attached image), with the upper-left image being the "idle" status.

Sprite.png.ba9473b5e0a9c89fb036155b01aeddcb.png

 

 

And I put this code in my player prefab file:

        this.animations.add("idle", [0]);
        this.animations.add("jump", [1]);
        this.landAnimation = this.animations.add("land", [0]);
        this.animations.add("run", [1,2,3]);

The problem is that my "idle" status is going to repeat frames 1,2,3 instead, again and again, as if the character is moving, and the other statuses are all [0] (what I wanted for "idle"). The result is always the same, whatever numbers I put into the arrays.

I am a bit stuck, and cannot figure out where the problem is...

Any help or ideas should be greatly appreciated. Thanks.

 

Link to comment
Share on other sites

First check that the frames are correct. Create a global reference (player) and run from the console, one line at a time:

player.frame = 0;
player.frame = 1;
player.frame = 2;
player.frame = 3;

Then play the animations one at a time:

player.animations.play('idle');
player.animations.play('run'); // …

 

Link to comment
Share on other sites

Thanks for the answer. Well, it's OK, now... I discovered that there is another file that is overwriting the prefab file behaviour... I am following a tutorial in a book... so it's not completely my fault... Thanks again.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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