Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This question already has an answer here:

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

share|improve this question

marked as duplicate by Byte56, Sean Middleditch, bummzack, Trevor Powell, Tetrad Mar 12 '13 at 20:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
You should consider rendering only the visible tiles/objects. related: gamedev.stackexchange.com/questions/48548/… stackoverflow.com/questions/7984389/… –  petervaz Mar 11 '13 at 15:40
    
Thanks for your responses and sorry for duplicate –  TM3P Mar 11 '13 at 15:56

1 Answer 1

up vote 3 down vote accepted

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.
share|improve this answer
    
Thanks, that's a technique I've never thought of. I'll code something similar some day –  TM3P Mar 11 '13 at 18:19
    
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. –  Pieter Geerkens Mar 11 '13 at 18:23
    
I'm sorry but i can't vote up, nor down :| –  TM3P Mar 11 '13 at 20:47

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