Jump to content
  • Advertisement
Sign in to follow this  

2D game mechanic question

This topic is 2864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!

I want to create a game in which rocks fall from the sky randomly in different positions and at different times?

Well I know a simple way to do that, but if I try to use a big number of rocks the game starts to lag...

So how can I do this dynamically?

Share this post


Link to post
Share on other sites
Advertisement
There's no way to answer the question with the information you've provided. If you want help with this, you'll have to provide quite a bit more info about the problem (e.g. platform, programming language(s), API(s), how many rocks is a 'big number', etc.).

Share this post


Link to post
Share on other sites
Could you outline in detail your game loop and rock-updating algorithm? do the rocks have collision with eachother?

Share this post


Link to post
Share on other sites
When user starts the game, all rocks positions are generated with coordinates like x = 5 ; y = -5 or x = 50 ; y = -1000.
Then in game loop, game keep increasing the y value of each rock so they will appear on the screen after a certain number of frames.

This is really expensive because I'm calculating the position of each rock each frame, even for rocks that aren't even visible to the player...

So I want to know the best, or one of the best, techniques to do this dynamically, like only updating the position of visible rocks...

Share this post


Link to post
Share on other sites
Reconsider what you are doing; the 'y' value acts as a delay, so why not make that delay time based and only add rocks to be processed when it is time for them to become active.

Share this post


Link to post
Share on other sites
Perhaps lower the number of rocks and only drop them around the player.

So if you have a large world and drop 1000 rocks. Limit it to, like, 50 rocks. And only drop them in the space around the character. So if the screen is like 200x400 (I have no idea what the androids screen is like) drop them in a 600x1200 area around the player, so that all sides are surrounded by falling rocks and the player isn't able to run really fast and dodge them.


+----------------+
| Falling Rocks |
| +------+ |
| |Player| |
| | | |
| | | |
| +------+ |
| |
+----------------+


Also to cut memory operations (I don't know exactly what your doing), don't create a new rock everytime one needs to fall. If a rock collides with the ground, don't delete and create a new one, simply move it back into the sky and drop it again. This way the phone won't have to allocate and delocate memory so fast.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!