Game Development Community

New game loop for torque 2D?

by Marcelo Panaro de Moraes Zamith · in Torque 2D Professional · 08/13/2013 (10:38 am) · 1 replies

I have some doubts about the torque 2d game loop:
1 - How does the torque 2d game loop work?
2 - Can I implement my own game loop inside torque 2d?

Does anyone know this?
dic

About the author

Recent Threads


#1
08/13/2013 (12:31 pm)
If you are developing a game using scripts, you do not have a game loop. Torque 2D is event driven, meaning all of your scripts will be based on events being triggered based on collision, schedules, and so on. You can create a scheduled loop in TorqueScript, but it is not a way to override core functionality like rendering and object ticking. You would use it more for checking event status at pre-determined invertals.

Inside of the source code, it's a bit more complex. The platform main loop starts. Then it runs the game loop, which is dedicated to processing events. Here's a really rough callstack:

void DefaultGame::mainLoop - Calls the process function for major systems like Platform, Net, TimeManager, and Game. This will then jump into GameInterface::processEvent()

GameInterface::processEvent - This primarily contains a switch statement that processes the last event. It has cases for mouse movement, input event, time event, and so on.

You eventually end up in DefaultGame::processTimeEvent. This is where time events, simulation ticks, and the root render call occur.

Now, I do not know how you define a game loop. If you describe what kind of actions you want to happen in your game loop, it will better help us determine where it needs to go.