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

2016/4/28

Frogger Game-Delaying movement

CuddlySpartan CuddlySpartan

2016/4/28

#
I am making a Frogger game and I am having difficulties delaying the movement of my objects. The "frog" that you control is a bee and the "cars" that can hit you are birds. I have my world set to 13 by 13 with each cell 50 pixels. I want to have the birds move from one side of the other and using move(1); moves them too quickly so I've been playing around trying to delay their movements. I've tried the below code, but when I use it, it lags the rest of the world and the more birds the slower they move and I can't control my bee anymore. Any help?
public void act() 
    {
        movement();
    }   
    public void movement()
    {
        move(1);
        try {
            Thread.sleep(300);
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    }
danpost danpost

2016/4/28

#
Using thread sleeping or greenfoot delaying will cause the entire project to "pause" for the given time. You either need to move the speed slider to a lower settting or use timers within the project to control the speed.
You need to login to post a reply.