Godot Version
Godot 4.2.2
Question
I’m working on a card game, where the cards are rendered by control nodes. I’m currently trying to lay out these cards on the screen, and running into a lot of issues with how control nodes work. Each card is instantiated as a scene with a control node at its base, but I can’t seem to figure out how to scale the cards to fit them into the layout, or how to use the control nodes in any context other than an empty scene without breaking their layout completely.
I’ve tried wrapping the card itself in a Node2D node to make it possible to scale the component, this however means that control node parents completely ignore the size of the card when using containers.
How do I set this up in a way that allows me to use the rendered cards as self contained components that can be scaled and laid out without breaking their own internal layout?
My card renderer scene is set up like this:
- Control, set to exact size
- TextureRect (background image, hardcoded size and position, anchor top left)
- PanelContainer (for description, anchored center bottom and position set for exact positioning
- Various Control components, all manually placed using Transform Position in editor
My scene layout where I instantiate these cards looks like this:
- Panel (full rect)
- MarginContainer
- HBoxContainer
- Cards
- HBoxContainer
- MarginContainer
Using the CardRenderer scene on its own for the cards means the scale and all transform options are greyed out, and the HBoxContainer doesn’t pick up the size of the cards wihen laying out.
If I wrap the CardRenderer scene in a Node2D node, I can scale with no issues but the HBoxContainer doesn’t pick it up at all for laying out.
If I wrap it in a Node2D and then wrap THAT in a Container node, I have to manually set the final size of the scaled Node2D card in pixels on the transform of the Container parent. This is a usability nightmare and feels like a bad hack.
If I change the node type for the CardRenderer’s base node to Container, the layout within the card breaks completely when I instantiate the scene. The same happens if I try to wrap it in another type of Container node before placing it in my main scene.
I’m completely lost and have been stuck on this for the past two weeks. Why does being a child of a container stop me from setting the scale of a control? Why is it so hard to create a component that I can just place in a container, scale, and have it be laid out as it should?