Hello!

Today we will see what a timeline is and how you can use it to create a series of events that will be launched one after another. We will also use the path that we already reviewed in the post, to create objects and send them along a given path, like in TD games.

Timeline

Timeline is created like any other entity in Game Maker. By right-clicking on the Timelines folder and then Create -> Timeline. I will name it tml_spawn.

timeline_create .

This is what the Timeline window looks like

timeline_props

You can add/remove elements using the Add and Remove buttons. The first element added will have a Moment of 0. Next, I’ll add another Moment but change its value to 60. Game Maker defaults to 60 frames per second. And accordingly, specifying 60 means that the second event will take place in 1 second after the previous one. If specified 120, it will mean 2 seconds, and so on. Now I will open Moment which has 0 and add the following code

instance_create_depth(x,y,1,obj_enemy)

This code will create an object based on the coordinates where the timeline will be placed. I will call Timeline in a circle to create objects, and I will leave the code in Moment with the value 60 empty to pause for 1 second between creating objects. In this case, I will create only one type of object, if necessary, you can create different types of objects with a different intervals. For example, a warrior appears in the first second, an archer in the second, a mage in the third, and so on in a loop.

Now we need to create an object that will run the timeline. To do this, I will create an obj_spawn object in the objects folder and add the Create event with the following code

timeline_index=tml_spawn
timeline_loop=true
timeline_running=true

First, we indicate which timeline we will run, then we make the timeline run in a loop and turn on the timeline. After that, the timeline needs to be added to the room at the point with which our objects will go.

path_start(pth_enemy, 5, path_action_stop, false)

Now let’s start the game and see how objects are created at one point and move along a given path

timeline_result

Video