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

2022/12/14

falling object

Rainescap Rainescap

2022/12/14

#
How do i make a falling object and make it so that it spawns in different spots in the x axis
danpost danpost

2022/12/15

#
Rainescap wrote...
How do i make a falling object and make it so that it spawns in different spots in the x axis
The following line in the act method of the class (Actor subclass) will make the instances of that class "fall":
setLocation(getX(), getY()+1);
The literal '1' can be adjusted up to increase the speed. The MyWorld class act method should be used to spawn the falling objects, using the following for the x-coordinate of placement:
int x = Greenfoot.getRandomNumber(getWidth());
You need to login to post a reply.