java - libGDX: How to render a tilemap? -
i draw map consisting of limited set of tiles in different zoom levels, google maps instance. reason why consider using tiles because map big , in highest magnification whole map big (about 15000 20000 pixels).
now thought creating quadtree organize tiles. each time frame drawn, quadtree logic evaluate tiles render, rendering time minimal. however, how organize map tile objects itself? when best load tiles? creating sprite each tile seems overkill, dimensions of tiles , position remains static. spritecache doesn't seem help in case, drawing subset of map each frame. also, there quite few pros , cons in several cases: when load tiles when launching application, take long time load of them , cache them in gpu (not considered tiles fit in memory). when load necessary tiles on runtime, suppose experience kind of lag when tiles beingness rendered.
is there "best practice" case this?
i know there not right or wrong reply this, hear other suggestions solving problem.
thanks!!!!
'how organize map tile objects itself?': a) grouping tiles areas; b) viewer/camera draws areas in view (like frustrum culling, not each tile, because it's expensive inquire each tile if on view); c) each drawn area draws tiles on right position (relatively area.position). here question 'when best load tiles?' solved answer: - best approach load sprites before draw phone call , area.tiles on view; - load sprites pool. tested such approach on map 1000 x 1000 tiles, viewer (active tiles) 3 x 3 area (90 x 90 tiles). , such approach doesn't matter performance how big map (while computer have memory:) ), viewer size matters...
if viewer have bigger dimension - pre-render whole area.tiles texture , draw straight 1 area.texture each visible area on each frame.
textures should loaded when app starts. textures linked tiles when viewer created , when moves 1 area up/down/left/right.
for (area area : viewer.areas) { (tile tile : area.tiles) { tile.texture = <loaded_texture> or tile.image = new libgdx.image(<loaded_texture>) or other appropriate tile object way } }
java opengl libgdx quadtree
No comments:
Post a Comment