Doing something in every frame
by Christos Karapiperis · in Torque X 2D · 02/05/2007 (11:23 am) · 6 replies
I am new to TorqueX but I can tell that the C# sensation feels good. I have a question. I know that there's a game loop in every game, a loop which contains methods like Render(), PreFrame(), PostFrame() and other similar methods. I assume that this counts for the TorqueX more or less, but it seems that the game loop is not directly accesible. Suppose I want to make an ItemManager class for doing some stuff to my items in every frame. How am I going to do it? I think that it has something to do with the ITickObject and the ProcessTick function but I am not sure. So my question is this: How can I make sure that a method of mine is going to be executed in every frame?
I hope you understood my question.Thanks in advance.
I hope you understood my question.Thanks in advance.
#2
02/05/2007 (11:32 pm)
I managed to do it late last night but your post was quite reassuring. Thanks a lot.
#3
Without using Link Points (I'm still working on that), I have a MovementObject (based off of the starter game sample) which implements the ITickObject interface. In every ProcessTick() call, I set the CenterPosition of the T2DSceneCamera to the player position. But when I move the player around (in my case, a space ship), I see a noticeable "jitter" as though the camera position isn't being updated every frame. I can exaggerate this jitter by purposefully not updating the camera position every frame. The jitter goes away as soon as I stop changing the camera's position.
I'm trying to find a reliable way to have the camera update on *every* frame.
02/25/2007 (10:59 pm)
Are you *sure* that ProcessTick() gets called every frame? I suspect that it doesn't, for the following reason:Without using Link Points (I'm still working on that), I have a MovementObject (based off of the starter game sample) which implements the ITickObject interface. In every ProcessTick() call, I set the CenterPosition of the T2DSceneCamera to the player position. But when I move the player around (in my case, a space ship), I see a noticeable "jitter" as though the camera position isn't being updated every frame. I can exaggerate this jitter by purposefully not updating the camera position every frame. The jitter goes away as soon as I stop changing the camera's position.
I'm trying to find a reliable way to have the camera update on *every* frame.
#4
02/25/2007 (11:05 pm)
ProcessTick does not get called on every frame. InterpolateTick should be called on every frame. Otherwise you can use UpdateAnimation which is also called every frame.
#5
02/25/2007 (11:11 pm)
Thank you for the clarification, Ben!
#6
02/26/2007 (12:17 am)
Also, you probably want to wait until _OnRegister (or _InitComponent, depending on what version you're using) to add the object to the process list, rather than doing it in the constructor.
Torque Owner Luke Larson
class MyClass, ITickObject { public void InterpolateTick(float k) { } public void ProcessTick(Move move, float dt) { //insert stuff to do } }For more information about these functions see this thread.
EDIT: Wait I almost forgot. In the constructor you will need to add this:
Now these should be fired every engine tick.