Game Development Community

In Scene Bars/Text/Info?

by Dan Rubenfield · in Torque X 2D · 06/30/2007 (7:27 am) · 10 replies

Any recommendations on how to get text or "health" bars in scene?

I'm trying to put information over objects that exist in the game world.


there are a few resources for GUIControls, but I'm unsure how one would adapt them to show in-scene as opposed to in-gui.

Any alternative approaches are appreciated.

#1
06/30/2007 (9:23 am)
The GUI is an overlay, Its just another render layer that lives on top of whatever is underneath it. In other words, You dont have to adapt your GUI controls at all, just make sure you have your controls pushed to the canvas while your scene is running if you want to see your GUI.
#2
07/01/2007 (1:41 am)
Yeah but it's an overlay to the "screen", not the "scene".

I want to put a life bar over something in the scene, have the user scroll the screen over to it and be able to see it.

All of the GUI stuff is stuck to the screen and won't render into the actual scene (AFAIK).

Make sense?
#3
07/01/2007 (2:55 am)
Hmmm, it might be easier to manage that whole process in the scene, give everything that needs a healthbar a component to detect when the mouse is over it and spawn (or unhide maybe?) a healthbar object on layer 0 of the scene.



Healthbars are easy to do that way, text is another story, what kind of text are you talking about?
#4
07/01/2007 (9:32 am)
Actually you can do this quite easily. I'm in the process of implementing text objects that spawn @ the charters locations, but I won't be implementing it for another week or so, maybe more.

Basically, you just have to get you GUI to "talk to" or your in scene objects, or vica versa. Once they give over thier coordinates, its just a matter of converting world-space to pixel space. I think theres some code on the forums that talk about this...

But before you go rushing off, why don't you tell us more about what you are trying to do so we can help with more specifics?
#5
07/02/2007 (4:31 am)
This is what I did actually.

I made guicontrols that were aware of scene object locations. That way, I can add/remove them as needed, as well as move them around the screen to match the object locations.


This gives me the capability of using full gui controls on any scene object, as long as it communicates properly to the UI system.


This function is my friend now -

public static Vector2 GetScreenCoordinates(Vector2 worldPosition)
{
T2DSceneCamera camera = T2DSceneGraph.Instance.Camera as T2DSceneCamera;
return Vector2.Multiply((worldPosition - camera.SceneMin) / (camera.SceneMax - camera.SceneMin), new Vector2(GUICanvas.Instance.Size.X, GUICanvas.Instance.Size.Y));
}
#6
07/17/2007 (1:45 am)
Any idea why these vibrate if I use physics velocity to move an object?

I assume it's a roundoff problem, but I'm unsure how to fix it..
#7
07/17/2007 (3:14 am)
Does sound like a rounding problem, could you put the move function in the GUIControl instead?
#8
07/17/2007 (4:32 am)
The gui already handles the updates. It sets the position of the control to the position of the object (after converting to screen space).
#9
07/17/2007 (7:31 am)
@Dan - Where are you updating the position, in ProcessTick? If so that's likely your problem. The screen will generally update faster than ProcessTick gets called (which happens at a fixed rate, about 30 times per second). In the frames that happen between ticks the physics system is interpolating to show the current location of objects, but if you aren't using InterpolateTick to update your GUI positions then they'll still be where you put them as of the last tick, and your GUI elements will look out of synch with your sceneobject elements during those intermediate ticks. If this is what's happening, the way to fix it is to either use the InterpolateTick method (which gets called for those "between" frames). Alternatively, you could implement the IAnimatedObject interface, create an UpdateAnimation method, and register for the animation callback, since that will get called every frame.
#10
07/17/2007 (8:39 am)
I'm actually updating in InterpolateTick.

Essentially, my playscreen ui does a quick check to see if any of the necessary UI bits are visible. if they are, it updates their position.