Graphical Window Sprites

version 1 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next

  • Section: Hyperlinking Sprites

    If we have also included Jeff Sheets' Graphic Links extension, sprites may be configured to be "hotlinked" so that they will trigger a predefined command input when the player clicks with the mouse on the area covered by the sprite. Once this extension has been included, we need only to specify that a sprite is "graphlink-active" and we may click on it. Graphical Window Sprites does all of the required bookkeeping automatically.

    A click on a sprite will not, however, have any effect unless we also define a "linked replacement-command" for the sprite, which is simply the command we wish to fire when the sprite is clicked. So, to complete the definition of the example sprite presented above, we would add the hyperlinking information:

        Mario is a sprite. The sprite-identity is Figure of Mario. The sprite coordinates are {58, 45}. Mario is display-active. The display-layer is 4. The sprite-scaling factor is 0.7500. Mario is graphlink-active. The linked replacement-command is "JUMP".

    And now, while the Mario sprite appears in the window, clicking on it with our mouse will result in the command "JUMP" being entered at the command prompt. Note that the entire area of the sprite--including transparent zones--is hotlinked in this way. Also note that a sprite is only available to be clicked on when it is actually displayed on the screen (i.e., it is display-active and has already been drawn to the window). A linked replacement-command of "" will be perceived by the player as having had no effect, and this is the default command for graphlink-active sprites. We can make a hyperlinked sprite once again unresponsive to clicks by changing it to "graphlink-inactive".

    We can also make replacement commands fire silently; that is, the command will not be printed to the input prompt and will not appear in the transcript. This functionality relies on a hack that changes the command prompt, for which reason we need to define a use option before we can employ such "silent" commands:

        Use silent replacement-commands

    Silent commands can be used alongside regular replacement commands. We simply indicate a command's silence by prefacing the command with "$-":

        The linked replacement-command is "$-ZOOM IN"

    We can then define actions as usual:

        Zooming in is an action out of world. Understand "zoom in" as zooming in.

    Note that the name of the action does not include the "$-"; the prefix is solely a marker for use in defining the linked replacement-command as silent.

    Silent commands should really be used only for actions that will not output any text whatsoever; as such, they are mainly intended for out-of-world actions that will affect only the graphical window, such as zooming in and out, switching to another view, bringing up a pop-up, or something similar. If we do wish to print text as a result of a silent command, we need to be aware that we may need to output a line break or paragraph break to produce the desired output.

    A graphlink-active sprite that overlaps another in the display layering system will supercede the lower sprite. That is, if Mario partially overlaps a hyperlinked mushroom, clicking within the boundaries of the rectangle that defines Mario will cause Mario's, rather than the mushroom's, linked replacement-command to be invoked.

    The background cannot be hyperlinked. We can, however, imitate a clickable background by including a fully transparent sprite image of the same dimensions as the background and placing it on the lowest display-layer (usually display-layer 1).

    A final note: if we will need to have more than 25 hyperlinked sprites active at a single moment, we need to extend the number of blank rows in the Table of Graphlink Glulx Replacement Commands. Graphic Window Sprites manages this table automatically, and we should not attempt to set entries in it directly--the table is rebuilt each time the sprite drawing rules are updated, so direct edits will be disregarded in any case.