Godot Version
4.7
Question
I am programming a card game that plays on a board. The board is made by tiles. I made each tile a ColorRect node.
The minimum size for the node is Vector2(155,155).
In the tile script, I made it so that when the card is placed on the tile, a copy of the card is created and resized to the size of the tile.
func _drop_data(at_position, data) -> void:
var cardOnTile = card.instantiate()
var tileRatio = size/cardOnTile.size
cardOnTile.scale = tileRatio
add_child(cardOnTile)
in Godot 4.7, i changed it to:
func _drop_data(at_position, data) -> void:
var cardOnTile = card.instantiate()
var tileRatio = custom_maximum_size/cardOnTile.size
cardOnTile.scale = tileRatio #it shrinks the card to the tile's size
add_child(cardOnTile)
As soon as I keep the parent node as a ColorRect, there is no problem. However I want to put some margins to the tiles and if I change it to PanelContainer or MarginContainer to add margins, the cards on the tile do not resize anymore.
The containers keep to 155x155px squares, but the cards do not resize to 155, and keep their size 350x350px, even if I set the custom_maximum_size to 155 by code:
cardOnTile.costum_maximum_size = Vector2(155,155)
The card’s node type is a Margin Container, whose custom_minimum_size is (350,350), and whose child is a sprite with the image of the card.
Is there a way to have the same effect that I with the ColorRectTile using Margin or Panel Containers, so that the image of the card does not overflow the custom_maximum_size of the tile?