How do you create rectangles and position them based on a 2D array?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BlackJitsu
:warning: Old Version Published before Godot 3 was released.

I have created a 2D array using the following code in Godot 3

for x in range(width):
	var col = []
	col.resize(height)
	screen.append(col)

for x in range(width):
	for y in range(height):
		screen[x][y]= 1

Where screen is declared outside of this code.

Honestly not even sure if this works, but I would like to draw rectangles with the same sizes on to the screen using this matrix. The size would be depending on the viewport size(Ex: You would take the amount of rows in the 2D array and divide it by the viewport’s height to get the size of the rectangles to display on screen)

:bust_in_silhouette: Reply From: ohmi

My preferred way of going about this is to create a rectangle (tile?) scene with a sprite. That way it can also hold values like position in the grid or neighbouring rectangles.

You could even have the sprite be only one pixel, then set the scale to whatever width and height you want.

Alright, thanks for your reply!

BlackJitsu | 2017-11-05 15:53