Login | Register

Timelines

August 4, 2006, 13:35 by Calle
[loading]
-->
<img src="http://gmtutorials.com/files/timelinescrn.PNG">

If you search for timeline in the manual, you will find these functions:
<b>timeline_add()</b> Adds a new time line. It returns the index of the time line.
<b>timeline_delete(ind)</b> Deletes the time line with the given index. Make sure no instances uses the time line in any room.
<b>timeline_moment_add(ind,step,codestr)</b> Adds a code action to the time line at moment step. codestr contains the code for the actions. If the step does not exist it is created. So you can add multiple code actions for the same moment.
<b>timeline_moment_clear(ind,step)</b> You can use this function to clear all the actions for a particular moment.

And if you search further, you will also find these:
<b>timeline_index</b> Index of the time line associated with the instance. You can set this to a particular time line to use that one. Set it to -1 to stop using a time line for the instance.
<b>timeline_position</b> Current position within the time line. You can change this to skip certain parts or to repeat parts.
<b>timeline_speed</b> Normally, in each step the position in the time line is increased by 1. You can change this amount by setting this variable to a different value. You can use real numbers like 0.5. If the value is larger than one, several moments can happen within the same time step. They will all be performed in the correct order, so no actions will be skipped.

You should have confidence in these few, simple, functions if you want to use timelines – which is a very easy method to line up levels and similar. As it says in the explanation of function timeline_speed the step of the timeline is increased by one in each real step.

As you know the standard value for room_speed is 30 steps each second, so normally 30 steps would be taken in the timeline each second. So if you want a monster to appear in 5 seconds then you add a step event in your time line that is room_speed*5, 30 * 5, and in it you put a code, for an instance, instance_create(x,y,monster).

As timeline_speed is changeable though, if you want to be really sure about that it will actually be 5 seconds you should calculate something like this: room_speed * timeline_speed * 5.

To start a timeline you must execute it within an instance. It will then be associated with this instance, and all code in the timeline will be executed from that object. You do it like this (in create event for an example):

timeline_index = timeline_name;

You can also create a timeline during game execution, if so it will return an ID and you would have to add the events through code as well, just like this:

timeline = timeline_add();
timeline_moment_add(timeline, room_speed*timeline_speed*5,”
show_message(‘Five seconds now, three seconds to next message’)”);
timeline_moment_add(timeline, room_speed*timeline_speed*8,”
show_message(‘Eight seconds now.’)”);


Any piece of code can be executed inside a timeline. See it as an alarm event that executes itself at specified moments.

Please ask any questions that you’d like to be answered.

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games