© 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_29

29. Sequences

Ben Tyers1  
(1)
Worthing, West Sussex, UK
 

Sequences allow you to program in a set sequence that can be applied to one or more assets. It can play sounds, move objects, and move and animate sprites. Generally, you’ll program this within the sequence editor rather than using GML.

Sequences are ideal for such things as:
  • Moving buttons in for a menu

  • Creating an effect, for example, when an enemy dies

  • Animated cut-scenes

  • Making a sprite rotate, like when collecting a bonus

  • A boss level enemy movement and attack sequence

  • Make a complex animation, like a swinging chain/rope

  • Firing an intricate bullet spread

  • Applying audio and graphical effects when a player collects an invincibility bonus

  • Playing several sound effects in a set order

Let’s start by creating a few assets that you’ll use in the example.

Load in a bird sprite spr_bird – there is no object for this, as shown in Figure 29-1, resizing to 192x137. Also set the origin as middle center:

A window titled Sprite s p r bird. A sprite s p r bird window has a name, image sizes at 192 widths and 137 heights with a frame per second of 30. It has a bird with a horn in the working space with the current frame 1 by 14.

Figure 29-1

Showing spr_bird setup

Next create a sound snd_bird, and load in a bird sound from the folder From YoYo Games.

Note

We won’t be using left room editor tab for a bit, so you can click the X to close, so you have more space available for setting up your sequence. (Just click a Layout in the top bar, then Reset Layout, and then click any room in the asset tree to get this back.)

Creating a Sequence

Now create a new sequence, and name it sq_example, it will look like that shown in Figure 29-2.

An s q sample screen of a blank sequence contains navigation tools at the top-left, an empty working window, and an empty timeline.

Figure 29-2

Showing a blank sequence

First thing you need to do is change the length of the sequence. It is currently set at a length of 60 (which at 60 steps per second is one second). Change to 300 (five seconds), as shown in Figure 29-3.

A text box at the top right of the sequence displays 300.

Figure 29-3

Setting a length for the sequence

Let’s jump straight in and add an asset. Click and drag the bird sprite from the assets into the location shown in Figure 29-4, you’ll notice that it is the left bottom of the gray square (this square represents a default room size, so placing here would mean the sequence starts in the bottom left of a room when we add it in later – if you are using a different room size, you can adjust this in the Preferences):

An illustration of grid form s q example of 1366 by 768. It has a bird with a horn at the bottom left of the screen.

Figure 29-4

Showing a sprite placed in the sequence

In the bottom part of the screen, you’ll see this sprite referenced on the tracking panel, as shown in Figure 29-5. This area will show any sprites, objects, sounds, etc. that you have added.

An illustration of two panels. The left panel has a track panel of s p r B. The right panel has the sequence timeline from 0 to 75 frames.

Figure 29-5

Showing an asset added to the sequence

In the middle section you’ll see an orange bar, this tells the sequence how long the asset is to be present in the sequence. It’s currently on a short period, so click and drag where shown in Figure 29-6.

An illustration of a sequence timeline sets from 0 to 75 frames. The input drags 0 to 25 frames, and the project sets to 60 frames per second.

Figure 29-6

Where to click and drag to extra time present

Click and drag up to the end of sequence, level with the red line as shown in Figure 29-7. This ensures that the asset will remain viewable and present for the whole sequence.

An illustration of sequence timeline sets from 225 to 300 frames. The input drags to 300 frames, and a text box at the top right reads 300.

Figure 29-7

Showing asset time set for whole sequence

You now want to move the time to the end of the sequence; there are a few methods for doing this, like clicking where the numbers are above the orange bar (as in Figure 29-8).

I prefer to enter a number into the time box. So enter 300 in the box as shown to go to the end of the sequence, as shown in Figure 29-8.

An illustration of a bird highlights with the box. The timeline at the bottom of the page ranges from 0 to 75 frames. Highlights 300 in the text area.

Figure 29-8

Showing how to move to time in the sequence

Now we’ll drag the sprite of the bird to the far right of the gray box, as shown in figure 29-9.

An illustration of a grid screen has a bird at the bottom right of the screen.

Figure 29-9

Showing bird in bottom right for sequence time 300

GameMaker will do all the animation needed to start this sprite at the bottom left for time position 0 and move it to the bottom right for time position 300. Press spacebar now and you’ll see it move.

Let’s set up to move up to the top middle of the gray box at the midway point (time 150).

So enter 150 in the box as before, and drag the bird to the top middle, as shown in Figure 29-10.

An illustration of a bird at the top right of the sequence as a time of 150. The s q example of 1366 by 768 and frame per second set to 60.

Figure 29-10

Showing a new position for the sprite as time 150

You can now press spacebar again to test.

Let’s make it more interesting by changing the scale of the image as it moves.

Click where shown in Figure 29-11 to get some options to pop up:

An illustration of a pane has the track panel as s p r bird and highlights the add parameter track option.

Figure 29-11

Showing where to click to select an option

Setting a Scale Curve

Select the Scale option, as indicated in Figure 29-12.

An illustration of the panel has s n d bird and s p r bird. S p r bird has a position option as X Y minus 127.74, minus 16772 pixels. Highlights the scale option from the dropdown option.

Figure 29-12

Showing where to find scale option

Click Scale then Convert To Curve, as shown in Figure 29-13.

An illustration of pane has the track panel s p r bird. Highlights scale option from the dropdown menu. A menu displays curves for x and y and covert to curve.

Figure 29-13

Setting up for curve for changing scale

Now again enter 150 in the box to go to the middle of the sequence, then click where shown to drag up so the curve looks like that shown in Figure 29-14.

An illustration of a sequence timeline sets from 0 to 300 frames. A line drags up to 150 frames from 0 to form a curve.

Figure 29-14

Dragging up to form a curve

This blue curve represents the X scale (think of it like image_xscale), you’ll also want to do this for the Y scale. Click as indicated in Figure 29-15 to select the Y scale:

An illustration has curve options with X and Y. It highlights Y options with a circle.

Figure 29-15

Selecting y scale

Make the curve the same as you did previously. When done, both curves should match up like that shown in Figure 29-16.

An illustration of a sequence timeline set from 0 to 300 frames. A line drags up to 150 frames from 0 to form a curve.

Figure 29-16

Showing x and y scales matching

You can now test by pressing spacebar again.

You can also add audio to a sequence, go to position 150 again by typing it in the time box.

First click in an empty area of the main window, so nothing is selected, then drag over the sound asset you created at the start of this chapter into the main sequence window.

It will now play this sound when the bird reaches the middle of its sequence – being both at the top middle and largest scale.

Presently, your sequence is set up to play once through, you can also set it up to repeat, or play and reverse continually. You can set this by clicking where shown in Figure 29-17.

An illustration has a loop option besides the rewind, play, and forward buttons.

Figure 29-17

Setting loop type

Note

Setting the loop type not only applies to the sequence preview, it also applies to the sequence when you use it in your game.

To add a sequence to a room, one method is to create a new Asset Layer and give it a name, for example, as shown in Figure 29-18.

A room editor tab has layers of room 1 dropdown menu and highlights sequence options.

Figure 29-18

Making a layer for putting your asset on

You can now drag your sequence from the resources tree onto this layer.

Note

To make positioning your sequence easier, you may want to turn off snapping to position, as shown in Figure 29-19.

An illustration of grid color, alpha, gird X and Y values at 32 and highlights snap options.

Figure 29-19

Turning off snap to make positioning of sequence easier

An example for this project is in the download resources.

You also add in objects and make them move around in preset sequences, in a similar fashion to moving sprites.

Basic Project

  1. A)

    Make eight stars that start at the center of the room and move outwards and out the room, make the stars increase in size as they do this.

     

Advance Project

  1. B)

    Make an animated skeleton move from the left to the right, jumping over static boxes as it does so. Play a jumping sound each time it jumps and stop the skeleton’s animation while it is jumping.

     

Useful Functions

layer_sequence_create()
layer_sequence_destroy()

Otherwise, I won’t be providing any functions for Sequences as it is beyond the scope of this book – covering just the basics would require a whole book on its own.

Even with just the basics you’ve learnt in this chapter, you’ll be able to create some pretty awesome effects, cool animations, cutscenes, and more.

Summary

You should now have a basic grasp of Sequences and have an idea of how capable they can be.

We’ve only covered the basics, but sequences are a very capable tool, so feel free to look more into what it has to offer.

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

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