Java 2D game -- simple but efficient way to load maps? -
i'm having problems on deciding way load preset maps simple game i'm testing, , i'd out of way (make clear) before tackle future projects.
i've reviewed code many tutorials , sources, code utilize when loading images , implementing maps designed either seemed complicated or simple(which seems inefficient)
examples are: 1.) (and inefficient) --> coding individual id on 2d array
int[][] map = { {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}, }; 2.) saving map file on notepad, , stored ascii characters or mutual characters.
3.) saving map on image file(i.e. png file paint) using colours determine tile. colours in image pixels translated rgb values read computer , converted tile.
i'd know whether i'm on thinking , these practices code. if not, can find online resources or source code(i don't have luxury books)
efficiency wise, load times, storage , other things shouln't matter much since simple programme (simple jumps, character movement, no mobs, no points) -- though id consider textures part of game in future.
edit: i'd add together i've finished, though not furnished simple 2d platformers using 3 methods before @ point in time. it's maybe theres improve way of doing things aren't advanced.
it depends on how big maps are.
for little stuff, hardcoding fine, finds natural limits in limits imposed class file format (max. size of initializer code).
any of other methods describe utilize more or less simple read format , (abuse) 3rd party programme (notepad, paint etc) "editor". efficiency wise aren't escpecially or bad, consider overhead of using ascii file relatively little (one byte per tile, in worst case have 2 tiles, 7 bits wasted) or in case of png free compression png format.
go fits project best - if complicated (many tiles, perchance multiple layers) , maps big consider making own editor (you should have code rendering in game, add together basic ui editing...) simplify editing. store in format find practical, raw byte arrays or serialized objects. won't matter in normal sized project single person can pull off.
java map 2d loading
No comments:
Post a Comment