i'm making a video game, and i'm having, i think, a concept problem. The game will be a platformer which will use tile maps, so to start i will create a mask matrix indicating the tiles to be loaded, and etc..., so my problem is, how to handle the scrolling? should i create a giant mask matrix indicating in each position of the whole level what is supposed to be loaded, and according to the position of the player, change the section to be drawed?? Is this a correct approach to this situation??

  • \$\begingroup\$ I'm not sure what a mask matrix is. If you explain it I will understand where you are and probably be able to answer your question. \$\endgroup\$ – ClassicThunder Jul 8 '13 at 15:48
  • \$\begingroup\$ @ClassicThunder I just mean a matrix defining in each position which kind of tile is supposed to be loaded. My question is if is ok, to have a giant file defining the whole level, or there is another more "elegant" way of handling this. \$\endgroup\$ – DGomez Jul 8 '13 at 15:59

Using tiles is a great idea first off (for a 2d game), as it allows you to effectively manage memory, loading, etc. and an effective part of using tiles for this reason IS to use a matrix, or map. In combination with a tileset for a given level or area, and with your base reflections (x and y plane) the matrix/map and tileset combo works a treat.

Three things need to be taken into account for this mechanism to be used effectively in a game however:

  1. If allowing 4/8 way scrolling, be careful that any actors/enemies/etc in the game are unloaded or carefully frozen/unfrozen in some way at the same time as mapped tiles when they are no longer in your viewport, particularly if you have AI/Pathfinding utilities. (The failure to compensate for this is visible in most, if not all 8 bit platform games where 8 way scrolling was allowed as enemies off screen fell through floors, etc.)

  2. Separate the concern's of scrolling/viewing from your concept of tiling. Tiling is a mechanism to deal with art assets prior to and after use by the game engine. I.e. This is a storage and load/unload pattern, rather than a rendering mechanism. Load the tiles you need to display and +100% in the x/y planes (for example) into memory, and create a texture centered around your character. Then scroll around the texture rather than by tile. Reload tiles after x/y has moved by more than (x) from start point. This has some extra benefits at the cost of the extra rendering to texture. I.e. you can apply transformations, blends, etc. to the texture off screen, and it prevents artefact-ing between tiles, which can occur at times.

  3. Depending on your target platform and coding abilities you may not wish to use actual tilesets and load individually from a larger palette. I would recommend against this as good practice, but that's me personally. I have seen 2d engines which did lazy loading of tiles as required, but I think loading a tileset with an area or level is a better way to use this pattern.

(Scrolling is handled elsewhere on this site amongst other places.)

| improve this answer | |

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