Graphical Window Sprites

version 1 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next

  • Section: Concepts: Sprites and "the Background"

    Graphical Window Sprites is based on the concept of the "sprite." In common graphics usage, a sprite is simply an independent bitmap image that comprises part of a larger scene, most commonly a two-dimensional image such as the moving characters in a video game. For the purposes of this extension, a sprite is a programmatic object that associates a given image with a number of attributes related to the way it should be displayed in Glulx graphical window. By defining sprite objects and giving Inform some rules about when to display them, we can simplify the construction of complex scenes that are made up of many discrete pieces. (For information about producing image files to use as sprites, see the Producing Images section below).

    The "background" is also an important concept. The background provides the coordinate system to which the sprites will be related. It can be defined using either an image (called the "background image") or by specifying a set of dimensions. Before sprites are drawn to the screen, Graphical Window Sprites checks to see how the background's dimensions compare to the size of the window itself, and scales and/or offsets the background so that it fits and is centered within the window. The same scaling and centering factors are then applied to each of the sprites. In this way, the coordinates we set for the display of a sprite are given according to the coordinate system of the background: If our background image measures 240 x 100 pixels, a sprite placed at (120,50) will sit approximately in the center of the background, even if the entire scene (i.e., background plus sprites) has been rescaled by 50% to fit in the window. Thus, in selecting the coordinates for our sprites, we need to relate them to the coordinate system of the background.

    To use Graphical Window Sprites, then, we define the background that our sprites will be superimposed on, then define the sprites themselves by indicating what image file each will display, the coordinates it be will be drawn at, and--if we like--how our sprite will be "layered" onscreen in relation to other sprites. We then write rules in our source text that will turn sprites "on" and "off" in appropriate situations (we can of course change a sprite's location or display size whenever we like). When we tell Inform to update to the graphics window, the extension will automatically locate the sprites we've turned on, arrange them in the layers we've specified, and draw them to the screen. If we wish, we can even identify a hyperlink command that will be invoked on the player's behalf when she clicks on a particular sprite in the graphical window.