Game Development Community

Adding "Update" type method to GUI class

by rwillis · in Torque X 2D · 11/02/2007 (9:18 pm) · 2 replies

I have my game play GUI class which I want to have a "ProcessTick" or "Update" type method added to it so I can constantly update GUI information as needed. What's the best method to go about this? Thanks.

#1
11/02/2007 (11:37 pm)
1. Have your class implement the ITickObject interface.

class MyGuiControl : GUIControl, ITickObject
{
}

2. Implement your logical update in the ProcessTick() method

public void ProcessTick(Move move, float elapsed)
{
     //insert logical updates, check game state, etc.
}
public void InterpolateTick(float k)
{
}

3. Start Requesting ticks to that ProcessTick() gets called.

public void OnWakeUp(GUIControl control)
{
    //request processing ticks
    ProcessList.Instance.AddTickCallback(this);
}

4. Need some custom drawing? Also override the OnRender() method

public override void OnRender(Vector2 offset, RectangleF updateRect)
{
    //draw a box
    DrawUtil.RectFill(new RectangleF(_position.X, _position.Y-4, _size.X, _size.Y), Color.Blue);

    base.OnRender(offset, updateRect);
}

That should do it.

John K.
#2
11/03/2007 (8:31 am)
Okay, I thought that addtickcallback could only be added to an "owner". Thanks again.