1
\$\begingroup\$

I am creating a 2D car racing game. (Yes, a Hill Climb Racing clone)

What I am doing right now is load 10% of the map every time the user gets to 7%. For example:

Imagine the map has 10km. (10000m)

When the game starts, the game loads the road from -100m to 1000m.

When the user gets to the 700m (7%) mark, the game deletes 0-500m and loads 1000m to 2000m (10%) (Having loaded from 500m to 2000m).

This will happen every 1000m from now on (1700m, 2700m, 3700m).

I used to create the whole world, and with this new method, I increased my mobile phone fps from 32-34 to stable 60 fps. BUT, every time the user is in the 700m mark, the game freezes for 0.55-0.60 seconds. (When I load/delete the new road).

Is there a better way (In terms of FPS (Performance)) to load the world?

\$\endgroup\$
2
\$\begingroup\$

You can find all what you need here Tile maps class, and read the section Rendering Tiled Maps

according to Libgdx docs:

Performance considerations

While we try to make the renderers as fast as possible, there are a few things you can consider to boost rendering performance.

Only use tiles from a single tile set in a layer. This will reduce texture binding. Mark tiles that do not need blending as opaque. At the moment you can only do this programmatically, we will provide ways to do it in the editor or automatically. Do not go overboard with the number of layers.

\$\endgroup\$
6
  • \$\begingroup\$ So I can use tools like Tiled to generate a world like this? I was doing it using Random class and a mathematical algorithm. \$\endgroup\$ – Mayuso Jan 18 '16 at 9:37
  • 1
    \$\begingroup\$ for sure you can I suggest to read all section on Tile maps \$\endgroup\$ – ZEE Jan 18 '16 at 9:39
  • 1
    \$\begingroup\$ Yes !! look you can use it \$\endgroup\$ – ZEE Jan 18 '16 at 9:41
  • 1
    \$\begingroup\$ github.com/libgdx/libgdx/wiki/Tile-maps#loading-tmxtiled-maps \$\endgroup\$ – ZEE Jan 18 '16 at 9:42
  • 1
    \$\begingroup\$ Thank you. I will try to learn about this and redesing the world generation in my game. I accepted your answer already, and will upvote it to make it more visible when stackexchange lets me do it :) \$\endgroup\$ – Mayuso Jan 18 '16 at 9:44
3
\$\begingroup\$

I don't think you can fix that "loading" issue, if your game has to open a file from HDD, load the content, parse it and draw it there's nothing to do that could speed it up. I would say that, the best you can do is store the whole map in memory and get chunks more often, like 100m sou you should be able to high speed reading from ram and the lag would disappear, and the chunk would be shorter than now, so the transference time would decrease.

Anyways, Why not procedural generation?

\$\endgroup\$
3
  • \$\begingroup\$ Thanks for your answer. I already got suggested to use Tile maps and I will give that a try. \$\endgroup\$ – Mayuso Jan 18 '16 at 10:43
  • \$\begingroup\$ Anyway, answering to your comment, I did not load a file from HDD, I created dinamically using trigonometry simple functions with random values to create hills and mountains. \$\endgroup\$ – Mayuso Jan 18 '16 at 10:44
  • \$\begingroup\$ To be honest, procedural generation is the way to go for this type of game. The goal is to get as much distance possible so your tilemap must be near endless. Or your map will contain an element that is unpassable or the players will 'finish' the game because they run out of map to drive. \$\endgroup\$ – Felsir Jan 18 '16 at 18:51
1
\$\begingroup\$

I reccomend you delete and load smaller pieces (~50m) at a time to keep a more stable (if not lower) fps.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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