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

2024/2/6

Moving Car

hamzanius hamzanius

2024/2/6

#
Hello, i am making a game where you can finish a track with a car. but i dont know how i can let the car move. (up down left and right) Can someone help me with this?
Kookaburra737 Kookaburra737

2024/2/7

#
Hey! Try this:
if (Greenfoot.isKeyDown("right"))
        {
            move(3);
        }
        if (Greenfoot.isKeyDown("left"))
        {
            move(-3);
        }
        if (Greenfoot.isKeyDown("up"))
        {
            setLocation(getX(), getY() - 3);
        }
        if (Greenfoot.isKeyDown("down"))
        {
            setLocation(getX(), getY() + 3);
        }
You need to login to post a reply.