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'm creating a game using libgdx on Eclipse that is similar to Ragdoll Avalanche. I'm looking for a way to generate falling objects like the triangles of Ragdoll Avalanche. All I know that i have to use an array but i dont know how to do it.

share|improve this question
You'll want to use some kind of random number generator (or something like perlin noise). Sounds to me like you need a little more programming experience, though, before anyone here can help you much. – stephelton Mar 19 '12 at 16:42
I know how to create sprites, but i do not know how to make sprites appear in a random order – Blue Mar 19 '12 at 17:20
up vote 1 down vote accepted

If all your objects are the same shape, all you have to do is pick a location to drop them from at the top of the screen and then lower them each update either by a fixed amount or by a velocity that increases via downward acceleration (gravity)

I haven't done any android development so this will be a little generic.

The easiest way to handle the objects is to create them at the top at a random position. Once you've done that add it to your collection. Each update move the objects downward via the logic you prefer(as mentioned above), and when an object gets past the bottom of the screen, remove it from the collection.

Now this is by far not the most efficient solution, but it's a good starting point. If you end up needing more efficiency, consider doing things like not removing from the collection and instead marking ones that pass the bottom as "dead". That way when you go to make a new one, you can first see if you have a dead one to recycle.

Remember though that everything in programming is a trade, the above example adds look-up time to creation while saving you on allocation and collection resizing. Don't solve for problems you don't have.

Also I would recommend looking up information about various collection types for your language to see how they are used and what their limitations are. You likely will want something dynamic that you can add to easily, but others may be able to call out specific implementation details.

share|improve this answer

In addition to Lunin's answer:

If you're looking to use a library instead of writing you're own collision detection/physics then you should use Box2D (its what Angry Birds uses). In fact, LibGDX has a port for Box2D physics engine. It handles collision detection, and physics simulation like the ragdoll body parts and falling triangles. You can search up some Box2D tutorials and look at Box2D tests in libgdx source or the VectorPinball demo. Note that Box2D was originally written in C++. If you learn how to use Box2D for this game,I think it will be very trivial and much easier to do.

share|improve this answer

The items spawned want to be objects with intrinsic position properties and a move method that can be called every frame or every set update to change the objects position downwards. As these are instantiated you can set up the y position such that they start just above the viable screen, and use a RandomNumber*screenwidth to determine the random x positions.

Using a loop that runs though the array you can check collisions and run the moveDown method for each object - you can also then check the positions of the objects to see if they are out of the screen to remove them, and count them up to see if you need to add more.

share|improve this answer

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.