#Fixing `Node`'s `GlobalTransform`s

20 messages · Page 1 of 1 (latest)

crimson trail
#

I have some Nodes creating a flexbox layout, and drawing the borders verifies they are laid out as expected. However, plotting the location of their computed GlobalTransforms seems to have them in an arbitrary location. I have one Node with children that are non-ui (Sprites) so ideally their location could be relative to their parent in some manner.

Thus, is it possible to specify some sort of "anchor" where the global transform of a node is relative to its UI box (e.g. top left), or is there some other method of making custom UI components position themselves properly?

compact hound
#

UI and World-space can't really be mixed like this. The GlobalTransform of the Node is in fact correct, bot it uses a different coordinate space, one fixed to the camera, so the UI stays fixed on the screen even if you move the camera around in the world.

#

You may be able to convert the Node GlobalTransform with Camera::viewport_to_world/_2d but i'm not sure whether UI actually uses viewport coordinates or a third thing

crimson trail
#

Right, thanks

#

Is there an idiomatic way this is supposed to be done then? Most of my game is non ui, I just have a few ui elements and wanted to add the rest of the game (almost like an iframe) to the flexbox

compact hound
#

Do you have a specific requirement which means you can't appraoch the UI as a overlay (which is the intended way)?

crimson trail
#

Not exactly, it's just more convenient because it ensures that no ui element will overlap (as all ui is outside the main game), centering is done properly, etc.

#

so I will do that if there's no other option

compact hound
#

Well, there is the concept of sub-views where you can make a camera render to less area than the entire window

crimson trail
#

hmm, kinda, thanks for that resource

#

I guess it's slightly different in that it's a puzzle game, so I want the whole puzzle rendered and it's not about framing the camera

#

just about aligning the puzzle relative under ui

compact hound
#

hmm, another alternative would be using a camera which renders to texture for the game, and using that texture as a UI image

#

thats a bit more involved as far as setup goes but its basically exactly what you want with extra steps

#

though its not intended for this kind of thing, so things like picking (finding which entity your mouse is over) might need some extra work

crimson trail
#

That's a smart idea that might work well in my use case actually, thanks

#

I'll give it a try and resolve this for now

compact hound
#

I'd imagine things like the Drag observer would be amazing for a puzzle game, so idk if it really does fit your usecase so well

crimson trail
#

the controls happen to be outside the game so it does here