© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
B. TyersGameMaker Fundamentalshttps://doi.org/10.1007/978-1-4842-8713-2_26

26. Timelines

Ben Tyers1  
(1)
Worthing, West Sussex, UK
 
Timelines are a great way to make something happen in a predefined order and at a certain time. You can set it up to execute any code you wish, hence you can make a multitude of actions happen when you wish. As the set up uses only a single asset, editing and changing it can be done quickly. You could use a timeline to
  • Spawn enemies at set times.

  • Create a sequence of effects.

  • Spawn health packs.

  • Fire a spread of bullets.

Creating a Timeline

You can create a Timeline in the same way you would any other asset, as shown in Figure 26-1.

An image of the listed options. Select Create option from the list, and it has a list of various tools. Select the timeline option.

Figure 26-1

Creating a timeline

You can then name your timeline, as shown in Figure 26-2.

A timeline window of timeline example. It has a name as a timeline example with a moment and description. 2 buttons, add and remove, are at the bottom.

Figure 26-2

Naming your timeline

You can now click Add to create what is known as Moment. Click Add and edit the Moment to 60, as shown in Figure 26-3. This value tells the program when it should execute the code. At a default game speed of 60, this code would execute after one second, a value of 600 would be run at 10 seconds.

A timeline window for timeline example. It has a name as a timeline example and a moment as 60. On the right, the timeline example moment as 60 g m l.

Figure 26-3

Showing a moment added

You can then put code into the moment, just as you would with any code, for example:
/// @description Create a firework
effect_create_above(ef_firework,room_width/2,room_height/2,5,c_red);

which after one second would create a firework in the middle of the room.

Your Timeline would then look like that shown in Figure 26-4.

A timeline window for timeline example. It has a name as a timeline example, a moment as 60, and a description as create a firework. On the right, the timeline example moment 60 g m l has 2 line codes.

Figure 26-4

Showing code added to a moment

You can also add/create other moments in the same way, for example, as shown in Figure 26-5.

A property window of timeline example. It has a name as a timeline example and four moments, and descriptions. 60, create a firework. 300, start music. 600, spawn enemy. 650, create a firework.

Figure 26-5

Showing additional moments added

Make a Timeline Play

You can make the timeline start by using
/// @description Start timeline
timeline_index = timeline_example;
timeline_position = 0;
timeline_running = true;
timeline_loop=true;

which would start the timeline and repeat until told otherwise.

The final line of the previous code can be changed to the following, so it plays through just once:
timeline_loop=false;
where setting:
timeline_running = false;

would stop the timeline.

If you have it on an endless loop and require a pause, you can add a moment like that shown in Figure 26-6, which will force the timeline to wait until that moment before looping:

A property window of timeline example. It has a name, 5 moments, and descriptions. Selects 900 moments and wait for bit description and executes the Moment 900 g m l with 1line code.

Figure 26-6

Creating a moment to allow a short pause

Basic Projects

  1. A)

    Create a firework display using effects. Add audio that plays so it matches the effect. Make the display loop through five times and then stop.

     

Advanced Projects

  1. B)

    Make an enemy patrol in a square pattern, shoot a melee of bullets each time it changes direction.

     

Useful Functions

You can create a timeline with:
example=timeline_add();

which would set the timeline to execute the given script after two seconds.

You’ll also find these useful:
timeline_size()
timeline_max_moment()
timeline_moment_add_script()

Summary

You now know how to make things happen at certain times in an orderly pattern.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.95.68