Graphical Window Sprites

version 1 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next

  • Section: Defining the Background

    We can select from one of two types of background. The default is the image background, which we define simply by specifying the "currently shown picture" (see the Simple Graphical Window documentation):

        Now the currently shown picture is Figure of Background

    The background image can be freely changed during the course of the game, but we need to remember that, because the background image defines the coordinate system for our sprites, sprites may scale differently with background images of different sizes. If all background images to be used with a set of sprites have the same pixel dimensions, there will be no change in sprite display when the background is changed.

    Our other option is simply to specify the dimensions of our coordinate system. To use this option, we first need to set the "grid-background" truth state to true:

        Now grid-background is true
    ...and now we can define the background size by specifying it directly using the grid-x and grid-y variables:

        Change grid-x to 250. Change grid-y to 200.

    The currently shown picture will not be drawn when we use the grid-background option. If we want an image to act as our backdrop, we need to define it as a sprite.

    If at any point we wish to change to using an image-based background, we reset the truth state to its default value:

        Now grid-background is false
    In this case, we do not need to make any change to the grid-x and grid-y variables; these are automatically updated when a background image is used. However, should we wish to return to using a grid background, we need to change the grid-x and grid-y variables as before when we do so.