BearNecessities
BearNecessities copied to clipboard
Use Matrix for Tile Map?
related #28
Matrices are used in most tile-based games afaik. For Elixir there is the Matrix modules which might be helpful. Not sure if this is something for us.
Some resources on this
- Tilemaps tuturial
- Tilemaps tuturial: Square tilemaps implementation (Static maps) source / demo
- http://technologies4.me//articles/viewport-culling-tile-map-a3/viewport-culling-methods-p1/
- https://gamedevelopment.tutsplus.com/tutorials/an-introduction-to-creating-a-tile-map-engine--gamedev-10900
Basic example from the demo above
const map = {
cols: 8,
rows: 8,
tsize: 64,
tiles: [
1, 3, 3, 3, 1, 1, 3, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 2, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 2, 1, 1, 1, 1,
1, 1, 1, 1, 2, 1, 1, 1,
1, 1, 1, 1, 2, 1, 1, 1,
1, 1, 1, 0, 0, 1, 1, 1
],
getTile: (col, row) => {
return this.tiles[row * map.cols + col]
}
};
translated to: