This site requires JavaScript, please enable it in your browser!
Greenfoot back
Gzuzfrk
Gzuzfrk wrote ...

2013/5/18

Key Control

Gzuzfrk Gzuzfrk

2013/5/18

#
How do I make it to where the code works? It only will switch images if I press left but the images wont switch if I press right
  public void checkKeyPress()
    {
        
        if(Greenfoot.isKeyDown("right"))
        {
            move(2);
            
           
            if(animationCounter % 1 == 0)
            animateRight();
            
            
           
        }
        else
        {
           setImage("Stand1.png");
           
        }
        
        if(Greenfoot.isKeyDown("left"))
        {
            move(-2);
            
            if(animationCounter % 1 == 0)
            animateLeft();
            
        }
        else
        {
           setImage("Stand1.png");
           
        }

       
}    
    public void animateRight()
    {
        
       
       
         if(frame == 1)
        {
            setImage(runLeft1);
            if(animationCounter % 4 == 0)
            frame = 2;
        }
        else if(frame == 2)
        {
            setImage(runLeft2);
            if(animationCounter % 4 == 0)
            frame = 3;
        }
        else if(frame == 3)
        {
            setImage(runLeft3);
            if(animationCounter % 4 == 0)
            frame = 4;
        }
        else if(frame == 4)
        {
            setImage(runLeft4);
            if(animationCounter % 4 == 0)
            frame = 5;
        }
        else if(frame == 5)
        {
            setImage(runLeft5);
            if(animationCounter % 4 == 0)
            frame = 6;
        }
       
        else if(frame == 6)
        {
            setImage(runLeft6);
            if(animationCounter % 4 == 0)
            frame = 7;
        }
        else if(frame == 7)
        {
            setImage(runLeft7);
            if(animationCounter % 4 == 0)
            frame = 8;
        }
        else if(frame == 8)
        {
            setImage(runLeft8);
            if(animationCounter % 4 == 0)
            frame = 9;
        }
        else if(frame == 9)
        {
            setImage(runLeft9);
            if(animationCounter % 4 == 0)
            frame = 1;
        }
        
    }
        public void animateLeft()
    {
        
       
       
         if(frame == 1)
        {
            setImage("Run5.png");
            if(animationCounter % 4 == 0)
            frame = 2;
        }
        else if(frame == 2)
        {
            setImage("Run6.png");
            if(animationCounter % 4 == 0)
            frame = 3;
        }
        else if(frame == 3)
        {
            setImage("Run7.png");
            if(animationCounter % 4 == 0)
            frame = 4;
        }
        else if(frame == 4)
        {
            setImage("Run8.png");
            if(animationCounter % 4 == 0)
            frame = 5;
        }
        else if(frame == 5)
        {
            setImage("Run9.png");
            if(animationCounter % 4 == 0)
            frame = 6;
        }
       
        else if(frame == 6)
        {
            setImage("Run11.png");
            if(animationCounter % 4 == 0)
            frame = 7;
        }
        else if(frame == 7)
        {
            setImage("Run12.png");
            if(animationCounter % 4 == 0)
            frame = 8;
        }
        else if(frame == 8)
        {
            setImage("Run13.png");
            if(animationCounter % 4 == 0)
            frame = 9;
        }
        else if(frame == 9)
        {
            setImage("Run14.png");
            if(animationCounter % 4 == 0)
            frame = 1;
        }
       
       
    }
You need to login to post a reply.