Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I followed the Rain Catcher tutorial from libGDX and I made some modifications to the code, allowing the rain drops to appear faster. But I cant figure out how to make the raindrops fall at random speeds.

How can I make random raindrops fall at different speeds? I also want the raindrops to accelerate when it gets closer to the bottom.

share|improve this question
up vote 4 down vote accepted

The first thing to do, would be to specify a velocity component for the raindrop class; which specifies how fast the raindrop falls. To apply this, try the following (assuming the velocity component is called yVelocity):

// Take this line
raindrop.y -= 200 *;
// Replace with something like
raindrop.y -= raindrop.yVelocity *;

You can set the yVelocity in the constructor of the raindrop using the random function. (See here for an example of how to use the random function to get a value within a range).

If you want only specific random raindrops to have a random speed applied to then; use the random function to determine whether the constructed raindrop is allowed to have a random speed applied, by checking that the random value falls within a certain range.

The following example applies a random velocity to roughly 1 in 10 raindrops.

if (Math.random() >= 0.9) {
    raindrop.yVelocity = //Random velocity calculation here;
else {
    raindrop.yVelocity = 200;

To have the raindrops move faster as they travel down the screen, simply increase yVelocity by a gravitational constant in the update call for each raindrop. :)

EDIT: I would recommend that you made Raindrop a class of it's own, as using rectangle directly in that fashion severely restricts what properties you can apply to the raindrops.

share|improve this answer
I would put it in a class of its own but since I'm not that experienced it will only create problems for me. – Blue Apr 18 '12 at 14:13
If you really must do it all inline; create a second collection (which uses floats/doubles) that has another iterator, and have this iterate simultaneously with your main iterator for the Rectangle collection. Then you can use the first iterator for the positions etc. And the second iterator for the yVelocity as given in my examples. – Jason H Apr 18 '12 at 16:53
yea I got everything to work on the desktop application but not on the android emulator so i asked another question… – Blue Apr 18 '12 at 17:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.