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

2015/3/31

I mant to animate a frog jumping

richyd012 richyd012

2015/3/31

#
so ive already got the animation of the frog moving perfectly just how i want it but i cant seem to stop the whole world from moving when it animates. when i use timers or counters the animations just don't works as well, like the frog does come bak to its original position when the key is released
import greenfoot.*;

/**
 * Write a description of class Frog here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Frog extends Actor

{
    private GreenfootImage image1;
    private int delayCount;
    
    public Frog()
    {
        image1 = new GreenfootImage("frogger.png");
        image1 = new GreenfootImage("frogger1.png");
        image1 = new GreenfootImage("frogger2.png");
        image1 = new GreenfootImage("frogger3.png");
    }   

    public void act() 
    {
        checkKeypress();
      
    }
   
   
    public void checkKeypress()
    {  

        int x = getX();
        int y = getY();

        if(Greenfoot.isKeyDown("right"))   
        {  
            setRotation(90);
            animate();
            setLocation(x + 50, y);
            Greenfoot.delay(3);
            setImage ("frogger.png");
        }  
        if(Greenfoot.isKeyDown("left")) 
        {  
            setRotation(-90);
            animate();
            setLocation(x - 50, y );
            Greenfoot.delay(3);
            setImage ("frogger.png");
        }  

        if (Greenfoot.isKeyDown("up") )  
        {         
            setRotation(0);
            animate();
            setLocation(x, y - 50);
            Greenfoot.delay(3);
            setImage ("frogger.png");
            
        }

        if (Greenfoot.isKeyDown("down"))
        {  
            setRotation(180);
            animate();
            setLocation(x, y + 50);
            Greenfoot.delay(3);
            setImage ("frogger.png");
        }  
    }  

    public void animate()
    {
        setImage ("frogger1.png");
        Greenfoot.delay(2);
        setImage ("frogger2.png");
        Greenfoot.delay(4);
        setImage ("frogger3.png");
    }
    
    
}
You need to login to post a reply.