C# Tween Children In Containers When Child is Add/Removed
Asked Answered
B

9

0

I want to make the other children slide to fill the position when a child is removed from a container. For example a HBoxContainer.

Is there a place I can do this within the container class? Or will have I have to create my own container class to handle this?

Belletrist answered 7/6, 2023 at 13:47 Comment(0)
L
0

Belletrist
Containers lock transforms of their children and handle their positioning internally, so you cant really interfere with it.
You'll need to make your own system.

Lipinski answered 7/6, 2023 at 13:55 Comment(0)
B
0

Lipinski Do you think this is something that the engine would want to have added? I'll create an issue unless it's a deliberate dsign decision.

Belletrist answered 7/6, 2023 at 13:57 Comment(0)
L
0

Belletrist I don't think they'll want to add something specific like this. Containers are meant and optimized for general control layouts. The thing you're asking for goes a bit beyond this and on the other hand it's not very hard to implement on your own.

Lipinski answered 7/6, 2023 at 14:5 Comment(0)
B
0

Lipinski What you say makes sense to me as they would just be for static use cases.

However, the built-in container classes will always be more performant. So it would be nice to have an override/hook for handling the movement logic, which looking at it, I assume Godot just sets the assigned position for each child. Just exposing a method like MoveChildren(Dictionary<Control, newPositions>) would do the job.

Just wondering as the new Tween system only came about with Godot 4, as is my understanding, so maybe they didn't have this in mind when they made Containers.

Belletrist answered 7/6, 2023 at 14:17 Comment(0)
L
0

Belletrist If you want to position children manually then there's no need to use a container. Besides adding something like this would introduce quite a bit of additional spatial and temporal complexity into already complex layout system, for the sole purpose of having an animation effect.

However, if you have a clear idea how something like this would operate, you can always try to make a feature proposal and see how it'll be received.

Lipinski answered 7/6, 2023 at 14:33 Comment(0)
B
0

Lipinski I don't want to position the children manually that's the thing. I want the positions that the controls give me just tweened. I can see issues like resizing the Container but again maybe that should be tweened.

I'll do some more thinking on it and see if I can come up with a proposal that makes sense.

Belletrist answered 7/6, 2023 at 14:41 Comment(0)
L
0

Also you can kinda hack it by parenting non-control nodes like sprites to invisible control nodes that are in the container, and then tween those non-control nodes. Or just make non-contained control nodes that use invisible container layout as a positioning reference. As I said, this is relatively easy to implement in numerous ways.

Lipinski answered 7/6, 2023 at 14:43 Comment(0)
B
0

Lipinski The second one probably makes the most sense, it's a good idea.

I'll probably go through the effor of making the proposal anyway, if it's not wanted then at least it's there for other people to see too.

Belletrist answered 7/6, 2023 at 14:49 Comment(0)
G
0

Belletrist I want to make the other children slide to fill the position when a child is removed from a container. For example a HBoxContainer.

Wouldn't a grid container fulfill this purpose? Now, given it doesn't feature any animation for it afaik. Which brings us to...

Belletrist Do you think this is something that the engine would want to have added? I'll create an issue unless it's a deliberate dsign decision.

You could always create an issue on the proposals repo and ask for the interpolation/animation be implemented for grid containers I guess.

Gaelan answered 8/6, 2023 at 4:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.