“Tasks” is a function used in Panda3D, which refer to: “The need to provide for certain game objects, execution loops.”
For example, when creating a character in a game, the programming of this character may have some functions that should be checked, and executed in every single frame.
Different game engines have different names, and ways to implement these procedures. Here we’ll see how it works in Panda3D.
Panda3D —————————–
sample 1:
To build a Task in Pand3D is very simple.
In line: self.taskMgr.add(self.taskFunction, “testing Task”), the task named “testing Task”, is created. And the function self.taskFunction is set as the function which is going to be called every frame.
It is free for the developer, choose the method he wants to set for the tasks, as well, decide the functions names as his wish.
The task function, in the sample above, has a mandatory parameter, called “task” and a return value, also required, which is a Task constant, in case, Task.cont.
sample 2:
In this last sample code, it is possible to see, how to modify a game object positioning properties (It worth mention that basically, any property might be edited during a task.) In this case, the x value is changed in 0.01, every single task execution, giving the illusion that the cube is moving towards the right.
Is possible to create some more specific behaviors in tasks, like, stopping the task execution after a while:
sample 3:
In this sample, the return value for the task function will be Task.cont (“Task.continue”), while the cube x position is less than 3. As soon the cube x position, become bigger than 3, the return value is gonna be Task.done, and the task will no longer be executed.
sample 4:
In this last sample, it is possible to see that the cube moves in intervals of two seconds. In this sample, we use the method ‘doMethodLater’, that allows the developer to set a time wait, till the task start be executed. And when the task is executed, a delay time (task.delayTime) is set to retard the next task execution.
Tasks run a major role in Panda3D games and are use in many situations. So… master them.