Graphical Window Sprites

version 1 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Section: Preloading Sprites

    By default, Graphical Window Sprites checks the dimensions of each active sprite every time the graphics window is updated. In other words, each time the window is redrawn, each sprite's size is evaluated and (if required) scaled to the proper size, then drawn. This could be considered wasteful, since for most applications the dimensions of the graphic associated with a sprite (the sprite-identity property) will not change during the course of play. In my tests, the arguably unnecessary calls to glk_image_get_info have had no noticeable impact on performance, but an option to preload sprites at the beginning of the game has been included even so. To take advantage of this option, we include this phrase in the source code:

        Use preloaded sprites

    When enabled, this will read in the dimensions of all sprites at the beginning of the game, storing their dimensions in the image-width and image-height properties. The dimensions will never again be checked when sprites are drawn, so we should be certain that we do not change the sprite-identity for any sprite in the course of the source text.