How to resize child together with parent?

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

Say I have 2 images:
1 - person sitting
2 - chair the person is sitting on

I need to overlap the images in a way so that the person is sitting on the chair. When I resize the person, the chair should follow. How can I do this in an easy way? I will have multiple children that must be resized along with the parent.

:bust_in_silhouette: Reply From: MisterMano

Please avoid using “latest” as the Godot version, because people might reach this question, having a similar problem, after a new version than the one you’re using is released.

As for the question proper, changing the parent node will usually change all its child nodes’ properties as well, in this case, the scale. If the nodes are all KinematicBody2D or Sprites or similar, changing the scale of the parent will change the scale of the children as well. Changing the child alone won’t change the parent.

player
→ chair (child of player)

Note that setting player.scale.x = 2 won’t change the child’s scale to the same value. If, in this example above, you set chair.scale.x = 0.5, you’ll see that it’ll revert to the normal size, since all its default values come from the parent.

Also keep in mind that a child node suffers any other transformations applied to the parent. So, making the chair the child of player will make it move, scale, rotate and everything else that happens to the player, which might not be desirable.

Perhaps the ideal solution would be to create something like this:

Node2D
→ Player (child of Node2D)
→ Chair (child of Node2D)

This way, you can scale Node2D and not worry about any other transformation that should be exclusive to the player to happen to whatever else you want to scale. The Node2D could be an YSort, too and scaling it will work.