Fill in empty tiles on 2d game load

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By capt_redbeard

I have a top down portrait 2d game that I am building. It is a fixed perspective so the camera never moves. My project settings are as follows:

Width: 720
Height: 1080
Orientation: portrait
Mode: 2d
Aspect: expand

I have filled in the viewport in the editor with my tiles, but depending on the screen size there will be empty grey tiles displayed. What I would like to do is on game load, detect the screen size and fill in those tiles. Or is there a better way to handle this for various phone screen sizes?

The simplest way would be to simply start with enough tiles defined to work correctly for your range of targeted resolutions. Is that not an option here?

jgodfrey | 2022-10-28 17:54

To clarify a bit more, I have a fixed size “game board” that is playable and I would like that to always be centered at the bottom of the screen then fill in the extra tiles above and around with random filler tiles.

The problem I am having with starting with enough tiles to work correctly for the range of targeted resolutions is the game board is always fixed to the top rather than the bottom.

capt_redbeard | 2022-10-30 21:13

What I am doing currently is in a script attached to my tilemap getting all the cells like this then drawing all my tiles -

var window_size = get_viewport().get_visible_rect().size
var no_of_y_cells = ceil(window_size.y / cell_size.y)
var y_cells = range(0, no_of_y_cells)
var no_of_x_cells = ceil(window_size.x/ cell_size.x)
var x_cells = range(0, no_of_x_cells)

for x_cell in x_cells:
		for y_cell in y_cells:
                      ...draw map using set_cell(x_cell, y_cell, ...)

capt_redbeard | 2022-10-30 22:15