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

2021/9/15

help

Nep Nep

2021/9/15

#
How to set an object to 20 pixels from the right and 100 from the top of the World. Make y increase by 40 pixels in a vertical line?
Nep Nep

2021/9/15

#
Using While Loop
danpost danpost

2021/9/15

#
Nep wrote...
How to set an object to 20 pixels from the right and 100 from the top of the World.
20 pixels from right would be width of world minus 20 (the World instance method getWidth() would be used). 100 from the top is just 100 (nothing more is needed).
Make y increase by 40 pixels in a vertical line?
Using While Loop
Are those instructions given??? A while loop would execute in entirety within one act cycle. The actor would teleport directly to its intended ending location unless you make use of the Greenfoot class delay method. You would also require a counter to count the steps taken and to exit the loop:
int steps = 0;
while (steps < 40)
{
    setLocation(getX(), getY()+1);
    Greenfoot.delay(1);
    steps++;
}
Note that NO other actions will be taken within your world during this movement. In future, please provide some attempted codes with your issue. It helps in others to gain some understanding of what is wanted and what you may need help with.
You need to login to post a reply.