1
\$\begingroup\$

I'm using this code to load a tiled map, composed of 1000x1000 32x32px tiles:

map = new TmxMapLoader().load("levels/xyz.tmx");

camera = new OrthographicCamera();

camera.setToOrtho(false, Constants.WORLD_WINDOW_SIZE.x / 32,
            Constants.WORLD_WINDOW_SIZE.y / 32);

renderer = new OrthogonalTiledMapRenderer(map, 1 / 32f);

renderer.getSpriteBatch().disableBlending();

renderer.setView(camera);

And this code for rendering:

camera.update();
renderer.setView(camera);   
renderer.render();

However, I have huge performance issues. How can I optimize this code ? Will splitting the map in multiple submaps help?

Greetings, TM3P

\$\endgroup\$
4
\$\begingroup\$

In addition to the techniques discussed in the link above, think about frame layering as well. In my game engine (board is 750 x 450 hexes of 32^2 pixels) I triple buffer the display into map, units, and highlights. On each Paint cycle:

  • MapBuffer is repainted only if the view has panned or zoomed;
  • UnitBuffer is refreshed from MapBuffer and units repainted only if one or more units has moved;
  • HighlightBuffer is refreshed from UnitBuffer and repainted; and
  • HighightBuffer is drawn to screen.
\$\endgroup\$
  • \$\begingroup\$ Thanks, that's a technique I've never thought of. I'll code something similar some day \$\endgroup\$ – UberLambda Mar 11 '13 at 18:19
  • \$\begingroup\$ I was initially intimidated when I realized it was necessary - but it turned out to be quite straightforward. P.S.: The best and most appreciated thank you is a vote. \$\endgroup\$ – Pieter Geerkens Mar 11 '13 at 18:23
  • \$\begingroup\$ I'm sorry but i can't vote up, nor down :| \$\endgroup\$ – UberLambda Mar 11 '13 at 20:47
  • \$\begingroup\$ Well, nice one. I got to GameDev after a few years of programming (I'm a professional WebDev), today I got my first big problem with my game, I just noticed that on mobile devices my game is running slow when I render a bigger scene (players can pick the size). :D \$\endgroup\$ – Damian Wojakowski Dec 14 '18 at 18:37

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