Game Development Community

Fixed position animation

by Thomas Vestergaard Nielsen · in Torque X 2D · 11/18/2010 (12:42 pm) · 4 replies

Hey everyone

I have a problem that I hope some of you can help me with.
My 2D game needs an energy bar in the top corner. This energy bar must always placed in front everything else on the screen, and it's animated.

To me, I have to ways of solving this:

1. Using a 2D overlay like a GUIBitmap, but can this some how be animated?

2. Using a "normal" T2DSceneObject which is some how positioned absolute on the screen. Can this be done?

I hope some of you out there can help me on this one :)

/Thomas

#1
11/23/2010 (3:06 am)
Make a component for the object you want to keep on-screen.
In the InterpolateTick() method, use SceneObject.WarpToPosition() to position it against the camera's location.

This will place the object in the center of the screen:
public virtual void InterpolateTick(float k)
{
    T2DSceneCamera camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>();
    if (camera == null) return;

    SceneObject.WarpToPosition(camera.CenterPosition, 0.0f);
}
#2
11/23/2010 (7:02 am)
Hi John

Thanks a lot. I actually tried that already and it works like a charm. The only problem is, when I use camera zoom I cannot seem to replace the object correctly.

/Thomas
#3
11/23/2010 (1:43 pm)
For the HUD I usually add the objects to a second scene view which overlays the gameplay scene view. The HUD is then not effected by the gameplay camera.

Alternatively I think someone did do an animated GUI bitmap (link?)
#4
11/24/2010 (7:00 am)
An animated GUI bitmap sounds perfect. I will look around for that.
I have not considered a second scene, that too sounds like a usable solution.