gm-docs-parser 1.0.0

A collection of typings for GameMaker Studio 2 manual pages
Documentation
<?xml version="1.0" encoding="utf-8" ?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>

  <script type="text/javascript" language="JavaScript">
    //<![CDATA[
    function reDo() {
      if (innerWidth != origWidth || innerHeight != origHeight)
        location.reload();
    }
    if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape")) {
      origWidth = innerWidth;
      origHeight = innerHeight;
      onresize = reDo;
    }
    onerror = null;
  //]]>
  </script>
  <style type="text/css">/*<![CDATA[*/

    < !-- div.WebHelpPopupMenu {
      position: absolute;
      left: 0px;
      top: 0px;
      z-index: 4;
      visibility: hidden;
    }

    p.WebHelpNavBar {
      text-align: right;
    }

    -->
  
/*]]>*/</style>

  <script type="text/javascript">//<![CDATA[

    gRootRelPath = "../../../..";
    gCommonRootRelPath = "../../../..";
    gTopicId = "9.2.2.9";
  
//]]></script>

  <script type="text/javascript" src="../../../../template/scripts/rh.min.js"></script>
  <script type="text/javascript" src="../../../../template/scripts/common.min.js"></script>
  <script type="text/javascript" src="../../../../template/scripts/topic.min.js"></script>
  <script type="text/javascript" src="../../../../template/scripts/topicwidgets.min.js"></script>
<script type="text/javascript" src="../../../../whxdata/projectsettings.js"></script>
  <link rel="stylesheet" type="text/css" href="../../../../template/styles/topic.min.css"/>
  <link rel="stylesheet" type="text/css" href="../../../../template/Charcoal_Grey/topicheader.css"/>
  <meta name="topic-status" content="Draft"/>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>Sequences</title>
  <meta name="generator" content="Adobe RoboHelp 2019"/>
  <link rel="stylesheet" href="../../../../assets/css/default.css" type="text/css"/>
  <meta name="rh-authors" content="Mark Alexander"/>
  <meta name="topic-comment" content="Page outlining the different functions and variables associated with Sequences"/>
  <meta name="rh-index-keywords" content=""/>
  <meta name="search-keywords" content="Sequences"/>
</head>

<body>
  <div class="topic-header rh-hide" id="rh-topic-header" onclick="rh._.goToFullLayout()">
    <div class="logo">
    </div>
    <div class="nav">
      <div class="title" title="Sequences">
        <span>Sequences</span>
      </div>
      <div class="gotohome" title="Click here to see this page in full context">
        <span>Click here to see this page in full context</span>
      </div>
    </div>
  </div>
  <div class="topic-header-shadow rh-hide" id="rh-topic-header-shadow"></div>



  <!--<div class="body-scroll" style="top: 150px;">-->
  <h1>Sequences</h1>
  <p>Sequences are usually created in the IDE using the <a href="../../../../The_Asset_Editors/Sequences.htm">Sequence editor</a>, but they can also be created and edited using code. However, before looking at the functions available, it&#39;s important
    to understand the way that sequences are defined in GameMaker and the different terms that will be used.</p>
  <p>To start with, at the top level, you have a <b>sequence element</b>. This is what you place on a layer in a room, either through the Room Editor or in code using the appropriate <a href="../Rooms/Sequence_Layers/Sequence_Layers.htm">layer functions</a>.
    The layer element has no real properties other than an element ID value, but this ID is required to use the above mentioned layer functions to change the sequence playback or to access the sequence data.</p>
  <p>Next you have <b>sequence objects</b> and <b>sequence instances</b> much like you have general objects and instances. A sequence <i>object</i> is the base resource as you created it in the <b>Asset Browser</b> or using the function <a href="sequence_create.htm"><tt>sequence_create()</tt></a>,
    and the sequence <i>instance</i> is the &quot;copy&quot; of that sequence object that has been placed in a room as an element on a layer. Think of sequence objects as blueprints and sequence instances as the creation from those blueprints. Sequence
    objects and instances are <a href="../../../GML_Overview/Structs.htm">structs</a> and - unlike regular objects - a sequence object struct can be edited at runtime, which will affect all further instances of that sequence when you create them as elements
    (and any editing done to a sequence object will <b>not</b> be reset by restarting the game or the room using the <tt>room_restart()</tt> or <tt>game_restart()</tt> functions). The sequence instance struct contains a few parameters to control playback
    and things (this is explained in more detail below) as well as the <b>sequence data</b> struct.</p>
  <p>Finally, as mentioned above, you have the <b>sequence data</b>, which is another struct. This struct contains <i>all</i> the data about the sequence. The tracks it contains, the propertys those tracks have, the playback speed and much more. The exact
    details of this structs contents are outlined below, but basically consists of <b>asset track</b> structs and <b>parameter track</b> structs which use <b>keyframe data</b> to actually perform actions while the sequence plays.</p>
  <p>Sequence elements are dealt with using the room <a href="../Rooms/Sequence_Layers/Sequence_Layers.htm">layer functions</a>, but for sequence objects, instances and data we have the following functions:</p>
  <p> </p>
  <ul class="colour">
    <li><a href="sequence_exists.htm">sequence_exists</a></li>
    <li><a href="sequence_create.htm">sequence_create</a></li>
    <li><a href="sequence_destroy.htm">sequence_destroy</a></li>
    <li><a href="sequence_get.htm">sequence_get</a></li>
    <li><a href="sequence_track_new.htm">sequence_track_new</a></li>
    <li><a href="sequence_keyframe_new.htm">sequence_keyframe_new</a></li>
    <li><a href="sequence_keyframedata_new.htm">sequence_keyframedata_new</a></li>
    <li><a href="sequence_get_objects.htm">sequence_get_objects</a></li>
    <li><a href="sequence_instance_override_object.htm">sequence_instance_override_object</a></li>
  </ul>
  <p> </p>
  <p>There is also a <strong>built-in variable</strong> associated with instances that can be used to determine of the instance has been used in a sequence or not:</p>
  <p> </p>
  <ul class="colour">
    <li><a href="in_sequence.htm">in_sequence</a></li>
  </ul>
  <p> </p>
  <p>Before using these functions to create or edit sequences, we recommend that you read the detailed descriptions given below for the struct properties. A general overview of how to create a new sequence would be:</p>
  <ul class="colour">
    <li>Create the new sequence object using the function <a href="sequence_create.htm"><tt>seqeunce_create()</tt></a> and store the sequence object index in a variable. This index gives you access to the sequence object struct.</li>
  </ul>
  <p class="code">myseq = sequence_create();</p>
  <ul class="colour">
    <li>Set the sequence object top level values like length, play mode, play speed, etc... For example:</li>
  </ul>
  <p class="code">myseq.length = 120;<br/> myseq.loopmode = seqplay_pingpong</p>
  <ul class="colour">
    <li>Before you can add tracks to the sequence object, you need to create them, so you&#39;d now create an array of <i>asset</i> tracks that have been defined with the function <a href="sequence_track_new.htm"><tt>sequence_track_new()</tt></a>. Note that
      in code, there is really no difference between asset tracks and parameter tracks - they are all simply tracks and how they behave will depend on the type od track you create and whether they are assigned as sub-tracks to a top level track or not.
      So, you would create a track for an asset, and then assign sub-tracks for the different parameters to it and these sub-tracks would act as the <i>parameter</i> tracks for the asset. The example below creates a single graphics asset track that will
      be added to the sequence later:</li>
  </ul>
  <p class="code">var mytracks = array_create(1);<br/> mytracks[0] = sequence_track_new(seqtracktype_graphic);</p>
  <ul class="colour">
    <li>Each asset track needs to have some data to tell the sequence how it will look, or its position , etc... and this is added in the form of <i>keyframes</i>. At the top level for an asset track, you can set keyframes for various things (listed in the
      section on the Track Struct, below), but note that as these are asset track keyframes, they won&#39;t be interpolated and will simply change the value they refer to when the given frame is reached. Each keyframe is a struct that is added to an array,
      and then this array is assigned to the asset track. To create the keyframe struct we would call the function <a href="sequence_keyframe_new.htm"><tt>sequence_keyframe_new()</tt></a> and to populate the keyframe with the required data, we would use
      the function <a href="sequence_keyframedata_new.htm"><tt>sequence_keyframedata_new()</tt></a>:</li>
  </ul>
  <p class="code">// Create a new keyframe struct for a graphics asset track and add it to an array (as you can have multiple keys in a frame)<br/> var graphickeys = array_create(1);<br/> graphickeys[0] = sequence_keyframe_new(seqtracktype_graphic);<br/> // Set the graphics
    keyframe top level data for the keyframe position and length, etc...<br/> graphickeys[0].frame = 0;<br/> graphickeys[0].length = 1;<br/> graphickeys[0].stretch = true;<br/> graphickeys[0].disabled = false;<br/> // Create the channel data that will
    go into this keyframe (again an array, as each key can have multiple channels of keyframe data)<br/> var graphickeydata = array_create(1);<br/> graphickeydata[0] = sequence_keyframedata_new(seqtracktype_graphic);<br/> graphickeydata[0].spriteIndex
    = spr_Platform;<br/> graphickeydata[0].channel = 0;<br/> // Add the keyframe data channels to the graphics track keyframe<br/> graphickeys[0].channels = graphickeydata;<br/> // Add the definied keyframes to the track<br/> mytracks[0].name = &quot;TestGraphicTrack&quot;;<br/>    mytracks[0].keyframes = graphickeys;</p>
  <ul class="colour">
    <li>We now need to create a parameter track which we&#39;ll assign as a sub-track to the graphics track we just created. This will be done in a similar way as shown above, only now we need to give the track a name that shows its purpose, in this case
      &quot;position&quot; as we&#39;ll be using this track to move the graphics track track over the course of the sequence animation frames:</li>
  </ul>
  <p class="code">// Create a new parameter track struct for the position of the graphic<br/> var paramtracks = array_create(1);<br/> paramtracks[0] = sequence_track_new(seqtracktype_real);<br/> paramtracks[0].name = &quot;position&quot;;<br/> paramtracks[0].interpolation
    = true;<br/> // Create the keyframe struct to hold the parameter channel data and set the frame position for the keyframe<br/> var paramkeys = array_create(2);<br/> paramkeys[0] = sequence_keyframe_new(seqtracktype_real);<br/> paramkeys[0].frame =
    0;<br/> paramkeys[1] = sequence_keyframe_new(seqtracktype_real);<br/> paramkeys[1].frame = 120;<br/> // Create the keyframe data structs<br/> var paramkeydata1 = array_create(2);<br/> paramkeydata1[0] = sequence_keyframedata_new(seqtracktype_real);<br/>    paramkeydata1[0].channel = 0; // Channel 0 for a position track is the X position<br/> paramkeydata1[0].value = 0;<br/> paramkeydata1[1] = sequence_keyframedata_new(seqtracktype_real);<br/> paramkeydata1[1].channel = 1; // Channel 1 for a position
    track is the Y position<br/> paramkeydata1[1].value = 0;<br/> var paramkeydata2 = array_create(2);<br/> paramkeydata2[0] = sequence_keyframedata_new(seqtracktype_real);<br/> paramkeydata2[0].channel = 0;<br/> paramkeydata2[0].value = room_width;<br/>    paramkeydata2[1] = sequence_keyframedata_new(seqtracktype_real);<br/> paramkeydata2[1].channel = 1;<br/> paramkeydata2[1].value = room_height;<br/> // Assign the keyframe data structs to the channels for each key<br/> paramkeys[0].channels = paramkeydata1;<br/>    paramkeys[1].channels = paramkeydata2;<br/> // Assign the keys to the parameter track<br/> paramtracks[0].keyframes = paramkeys;</p>
  <ul class="colour">
    <li>With that done, the final thing to do is assign the parameter track as a sub-track to our main graphics asset track that we created at the beginning and then assign these tracks to the sequence which we can then create an instance of in the room:</li>
  </ul>
  <p class="code">mytracks[0].tracks = paramtracks;<br/> myseq.tracks = mytracks;<br/> layer_sequence_create(&quot;Assets_1&quot;, 0, 0, myseq);</p>
  <p>The above instructions create a very simple sequence object that draws a sprite at the (0, 0) position <i>of the sequence</i> and then moves it to the bottom-right corner and back in a loop. As mentioned, there are a number of places where you need
    to access different structs to give or get data about the sequence, and the sections below list all the different properties that these structs contain:</p>
  <ul class="colour">
    <li><a name="object"></a><a href="Sequence_Structs/The_Sequence_Object_Struct.htm"><label for="1">The Sequence Object Struct</label></a></li>
    <li><a name="instance"></a><a href="Sequence_Structs/The_Sequence_Instance_Struct.htm"><label for="2">The Sequence Instance Struct</label></a></li>
    <li><a name="track"></a><a href="Sequence_Structs/The_Track_Struct.htm"><label for="3">The Track Struct</label></a></li>
    <li><a name="keyframe"></a><a href="Sequence_Structs/The_Keyframe_Struct.htm"><label for="4">The Keyframe Struct</label></a></li>
    <li><a name="keyframe_data"></a><a href="Sequence_Structs/The_Keyframe_Data_Struct.htm"><label for="5">The Keyframe Data Struct</label></a></li>
  </ul>
  <p> </p>
  <p>Finally, it is possible to add code to sequences that can be triggered as either an <strong>event</strong> a <strong>moment</strong> or as a <strong>broadcast message</strong>. This is explained fully on the following page:</p>
  <ul class="colour">
    <li><a href="Sequence_Events_Moments_Broadcast.htm">Events, Moments and Broadcast Messages</a></li>
  </ul>
  <p> </p>
  <p> </p>
  <p> </p>
  <div class="footer">
    <div class="buttons">
      <div class="clear">
        <div style="float:left">Back: <a href="../Asset_Management.htm">Asset Management</a></div>
        <div style="float:right">Next: <a href="../Fonts/Fonts.htm">Fonts</a></div>
      </div>
    </div>
    <h5>© Copyright YoYo Games Ltd. 2020 All Rights Reserved</h5>
  </div>
  <!-- KEYWORDS
Sequences
-->
  <!-- TAGS
sequence_functions
-->

</body></html>