0 votes

Hello! My objective is to create a responsive container of any size and in it a 2D grid of ColorRects that fills the full size of the container.

GridContainer shrinks the ColorRects to size 0 if Min Size is 0, so I tried to set the Min Size as proportional to the size of the container using GridContainer.get_rect().size. The problem is that with some configurations (for example setting Layout Full Rect) of the GridContainer this size returns 0, even if the real size of the container is not 0. This was an unexpected behaviour for me.

How should I go about creating my grid? Maybe GridContainer is not the way, maybe I need additional containers or maybe there is another function that returns the size of the container.

Godot version 3.3.4.stable.official
in Engine by (21 points)

Is this going to be fundament of your project ?
Did You consider using TileMap ?
Why do You need to change size of this grid in-game ?

I consider using TileMap but hasn't tried because it's not what I need, I don't need predefined tiles, I need rects that I can change their color from scripts.

The size change may be needed for making the grid responsive to different window sizes.

But TileMap is most responsive node script-wise. It is has many methods that make elastic uses of it, while Control nodes are much more stiff. It is easy to make a system detecting your clicks and changing color of chosen tile. You can overlay more than one TIlemaps to create additional functionality. Window size is not a problem, You will adapt it in Viewport settings. Tilemap would only have problem with rects of different sizes, or with changing real global size midgame.

Maybe You can tell more about Your project ? What will those rects do, how do they interact with each other ?

Basically there are a couple of variable values that determine the color of each tile in a 10x10 grid of tiles. The color of each tile is determined once the grid is created, so the only needed functionality is determine the color based on its x, y coordinate on the grid (and the other values).

For example the colors of the tiles could be Color(ax/9, ba, a*y/9) where x, y is the grid position of the tile and a, b other game variables. All that needs to be done is generate the tiles of each corresponding color.

I'll look into how to implement this with tilemaps if you insist, but it didn't seem like the right choice to me.

This might sound obvious but did you try to set your ColorRects to expand instead of setting a minimum size?

Yes, doesn't work, the grid still sets their size as their min size.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.