Jump to content

Multiple animations in 1 player with multiple jsons/pngs


Miu
 Share

Recommended Posts

Hi there,

 

I tried to add multiple animations in one player, here is how i wanted to do:

 

in preload function:

game.load.atlasJSONArray('megaman_left','./assets/charset/left.png','./assets/json/left.json'); game.load.atlasJSONArray('megaman_idle','./assets/charset/idle.png','./assets/json/idle.json');        game.load.atlasJSONArray('megaman_right','./assets/charset/right.png','./assets/json/right.json');

in create function:

 player = game.add.sprite( 30, 200, 'megaman_idle'); player.animations.add('run_right'); player.animations.add('idle'); player.animations.add('run_left');

in update function:

    if (keytouch.left.isDown)    {        player.animations.play('run_left',13,true);        player.body.velocity.x = -350;    }    else if (keytouch.right.isDown)    {        player.animations.play('run_right', 13, true);        player.body.velocity.x = 350;    }    else    {        player.animations.play('idle', 2, true);    }

And, as i expected, this is only playing idle animation, even if i press one of the keys.

 

So here is my question : 

 

can I add multiple animations with multiple png and json files in one player object?

 

i looked into the doc, can't find something like player.animations.add(...) to load with multiple files.

 

Thank you for your help :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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