how to customize tile map size ingame

Godot Version

4.6.3

Question

Hi! I was trying to make a minesweeper game as a little practice and I thought of using a Tile Map node but it seems it's best used when the amount of tiles during gameplay are set in stone.

The thing is I want the player to be able to pick between easy, medium hard and custom difficulty. In the latter they would choose the amount of rows, columns and bombs so I have a rough idea for the logic of the game but I don't know how I would scale the sprites if they chose a Really Big board.

So do you know about a way of resizing the amount of tiles in a tile map? Or any suggestion about doing this with arrays?

You may have start out small. See if you can add a cell using an empty TileMaplayer using set_cell. Make sure the TilemapLayer has a tileset configured

Once you achieved that (I promise quite a puzzle), maybe the next steps will start to fall into place.

(Edit) Strictly speaking, the TileMapLayer has no size, other than derived from the cells it has assigned: the topmost, the leftmost, the rightmost, and the … bottommost.

Just a few thoughts:

  • don’t use TileMap in new games, it is deprecated. Use TileMapLayer exclusively
  • tiles: MineSweeper has a fixed, limited amount of different tiles: hidden, flagged, mine, triggered mine, zero to 8 adjacent mines are a total 13 different tiles
  • cells: what varies is the number of cells that the player sees:
    • easy: 9x9 = 81 cells, 10 mines
    • medium: 16x16 = 256 cells, 40 mines
    • hard: 16x30 = 480 cells, 99 mines
  • while it might be difficult to change the number of tiles at runtime, the number of cells can be changed anytime (actually, TileMapLayer has no method to set bounds for the number of cells, but you can call get_used_rect() to determine the region that contains cells).

There is a limit to the number of cells in TileMapLayer because the cell coordinates are integer values (about -2_000_000_000 to +2_000_000_000) and there are further restrictions if you want to save a TileMapLayer (only the coordinate range from -32_000 to 32_000 is saved - but this still means there are about 4_000_000_000 cells in total).

But probably no player would want to play MineSweeper on a grid exceeding a few thousand cells.

Just wondering how you were doing so far.

This other question about using GUI Control nodes for a Plants versus Zombies style game, reminded me of your question:

It makes a lot of sense for a minesweeper as well, though I never tried creating a very big GridContainer