Jump to content

sprite animation doesnt work properly


Aicha
 Share

Recommended Posts

Hello everyone , im sorry for my english  so im pretty new to phaser3 and i want to create  educational coding game for kids using typescript ,the kid should drag the arrows and drag them into places and then hit the button run so i declared an array  to stock every arrow (image) that he dropped and then when run is clicked,  i itterate the  array and in function of the image's name the sprite get animated 

my code looks like this :

//paly is the run button //
    this.play.on('pointerdown', () => {

      for (var i = 0; i < array.length ; i++) {
        console.log(array);
        switch (array[i]) {
          case left: {

            this.player.setVelocityX(5);
            player.anims.play('left', true);
           break;
              }
          case right: {
                this.player.setVelocityX(5);
                player.anims.play('right', true);
                break;                    
                   }                      
            }
          } }

the images are stored but when i hit run the sprite is animated by the last animation like if my array is like this   {'left','left','right'}  just the right animation is getting excuted ,please im stuck help me !!! 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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