sbacuse15

Animating Sprites

Recommended Posts

I'm trying to add some new animations by adding a new "if" section in my "update:function" code. All of my "walking" and "sprinting" animations following the first "if" section play as they should. However, when I attempt to animate my crutch attacks under the second "if" section, only the first frame of those animations is played. I'm using the same attack button because it's the same attack being animated in all directions. I combo'd with my arrow keys so that I could use the same attack key. When I change them to all to "else if" statements under my first "if" section they don't play because it is my understanding that once a key is used in an "if" statement all other attempts to use that key under that section will be ignored. My code is listed below. Solution?

 

if(cursors.left.isDown)
        {
            player.body.velocity.x = -200;
            player.scale.setTo(.7, .7);
            player.play('walking');

        }
        else if(cursors.right.isDown)
        {                
            player.body.velocity.x = 200;
            player.scale.setTo(-.7, .7);
            player.play('walking');
        }
        else if(cursors.down.isDown)
        {               
            player.body.velocity.y = 200;
            player.scale.setTo(.7, .7);
            player.play('forward');            
        }
        else if(cursors.up.isDown)
        {              
            player.body.velocity.y = -200;
            player.scale.setTo(.7, .7);
            player.play('backward');
        }
        else if(sprintl.isDown)
        {              
            player.body.velocity.x = -400;
            player.scale.setTo(.7, .7);
            player.play('sprinting');
        }
        else if(sprintr.isDown)
        {             
            player.body.velocity.x = 400;
            player.scale.setTo(-.7, .7);
            player.play('sprinting');
        }
        else if(sprintu.isDown)
        {
            player.body.velocity.y = -400;
            player.scale.setTo(.7, .7);
            player.play('backsprint');
        }
        else if(sprintd.isDown)
        {
            player.body.velocity.y = 400;
            player.scale.setTo(.7, .7);
            player.play('forwardsprint');
        }        

        else{
            player.animations.stop();
            player.frame = 29
            player.body.velocity.y = 0;
        }    

    if(cursors.left.isDown && fireButton.isDown)
        {
            player.body.velocity.x = -50;            
            player.play('sidecrutch');
        }
        
        else if(cursors.right.isDown && fireButton.isDown)
        {
            player.body.velocity.x = 50;            
            player.play('sidecrutch');
        }
        

          else if(cursors.down.isDown && fireButton.isDown)
          {        
            player.body.velocity.y = 50;            
            player.play('frontcrutch');
            }
            
          else if(cursors.up.isDown && fireButton.isDown)
          {
            player.body.velocity.y = -50;            
            player.play('backcrutch');

            }                    
 

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.