Game Development Community

Floating HUDlike things

by Tim Scheiman · in Torque Game Builder · 01/17/2006 (8:20 pm) · 10 replies

A fellow once said "you can mount anything to anything within T2D and the camera is no exception"...

Well, you can't mount anything to a sceneWindow... : ) (yeah I know... completely different system, etc.)

I'm trying to get some HUDlike images floating along happily above my scene, in a world where my camera is mounted to my player object, and the player rotates around going in all directions (while staying nicely in the center).

I tried mounting to the player as well, figuring he was perfectly centered so it'd be ok, but as he rotates around the offset of the mount rotates around also, and I can't seem to fix that by any combination of parameters passed into the mount function (I can keep the image from rotating, but not the mount offset).

Do I need to mount some invisible thing to the player at a 0.0 0.0 offset that doesn't track rotation and then mount HUDlike things TO that object? This seems like it'd work, but I'm just wondering if anyone has a less ugly way of implementing this in script.

Thanks in advance for any random thoughts on the matter.

#1
01/17/2006 (8:44 pm)
Tim,

I ran into this problem myself and here's how I solved it. There is probably a more elegent solution involving only one scenegraph and some camrea view offsetting to be found, but i didn't think of it at that point.

1. Create a second scenegraph and scenewindow.
2. Create the hud elements and add them to the second scenegraph.
3. At this point you've got your game scenewindow and graph and your hud scenewindow and graph.
4. Make sure both scenewindows are the same size and visible on screen.
5. Align your elemnts how you like them in the second scenewindows view.
5. You have a camera independent overlay for your hud stuff!
6. Play away!

Hope this helps,

-Justin
#2
01/17/2006 (10:02 pm)
I did as suggested a while back for a different part of my HUD (a bar across the bottom), but I found that it is difficult to control priority between scenegraphs in two different windows.... If for instance I want some things that are in scenegraph A to overlap things in scenegraph B, but also sometimes the other way around.

For now I've done the "invisible mount point" as described above, and it works very well for me so far.

By the way -- are you aware of any overhead to having a second window and scenegraph (assuming it is doing very little) that could justify redoing the bar across the bottom that I implemented that way?

Thanks,

-Tim
#3
01/17/2006 (11:03 pm)
You can mount gui images to a linkPoint and then not track rotation.

- Jesse
#4
01/18/2006 (5:15 am)
Correct, if I understand the problem correctly, you can attach GUI elements to objects as per my plan here (GUI Attachment Movies).

Here's the extract from that plan...

------------------------------------------------------------------------------------------------------------------

Okay, if mouse-events aren't your thing then maybe you're interested in more dynamic GUIs for your games/apps? As T2D'ers will know, the GUI system lives in a pixel-space on the Canvas whereas T2D objects live in a special world-space and never shall the twain meet! In-fact T2D renders scenes in a specially designed GUI control itself but the objects live within it. and there's no interaction (apart from the mouse) with other rendered elements. Well, that's about to change forever.

Imagine being able to tell ANY of your T2D objects that you want to attach ANY GUI control to it irrespective of the GUI control having lots of nice children like buttons or even a T2D scene GUI control! Well you don't have to imagine because you can now do it.

With a single function you can now attach/detach any GUI control (and all its children) to a T2D Object with options for sizing the GUI Control to the size of the T2D Object or not so it's left as it was defined but track the T2D objects position. T2D will take control of this GUI hierarchy and move it in T2D world-space and clip it to the T2D scenes' window. This means that you can effectively have standard TGE GUI Elements within the scene and yes .... they work as normal; at least they do if you can catch them as demonstrated here...

T2D GUI Attachment Movie #1

Notice that I start by showing that they are real controls by clicking/selecting/typing. I linked the command from the top-left button so that it attached the GUI to the object moving in the background. Notice how the GUI sizes with the T2D object and that the children resize accordingly although I've only threw this GUI control together so you get some odd alignment with the children controls as you would if you resized it normally.

To show you just how flexible the system i,s I took the space-scroller demo and created a handful of T2D scene-windows all pointing to the running space-scroller scenegraph. I then created a new scene/window and attached the T2D windows to some bouncing objects within it. Again, script is practically nothing and here's the result...

T2D GUI Attachment Movie #2

Note that I'm actually playing the space-scroller demo in the background albeit badly! Great stuff!

------------------------------------------------------------------------------------------------------------------

- Melv.
#5
01/18/2006 (7:06 am)
Well what I was attaching at the moment only needed to be a staticSprite, but this is useful and interesting news to me as well for when I need more complicated things down the road (especially considering how long the Torque community has been adding different GUI objects). Thank you!
#6
01/18/2006 (12:26 pm)
Examples of things like this would be nice to have on TDN, even if it seems like common sense to some of you...
#7
01/18/2006 (1:30 pm)
In the RTS tut on TDN I attach three GUI Controls to the units to work as name labels, and hp bars.
#8
01/18/2006 (10:16 pm)
Thanks Matt, that's a good start and it helps me a lot. I hope that eventually we will have a spot on TDN for non obvious tricks or features to be explained on their own instead of as a part of the bigger tutorials.
#9
01/19/2006 (7:47 pm)
I agree with Joe on this one... I'm sure in the end there will be a LOT of wisdom in each of the genre specific tutorials... but I won't think to read through the RTS tutorial if I'm trying to add elements to my platformer or word-game. A little "So you want to _______?" section would section it all out nicely into bits for us inexperienced folk to get to easier. I guess "searching" the TDN would work, but the whole thing is so awkward... meh.
#10
01/20/2006 (6:38 am)
The thing I would like to add is that even when search gets you what you want it's often in a specific context within the example. I.e. it's example code specific.

An example of what was really useful to me is the tutorial by Matt L. about mounting an object to the mouse. It was just a box moving around the blank screen, but it was so simple that it was easy for me to think of it in context of my own project.