Home > Articles > Programming

📄 Contents

  1. How Programs Are Structured
  2. Method Main ( )
  3. Using Sprites to Display Graphics for Games
  4. Coordinate System
  • Print
  • + Share This
This chapter is from the book

Using Sprites to Display Graphics for Games

Define myUFO As Sprite

As we noted, the preceding instruction simply tells Phrogram that myUFO is a graphical object. Phrogram needs to know what myUFO is so that it knows the kinds of things it can do with myUFO. But, you may ask, what is a sprite? Drag your mouse over the word Sprite in your program and you will see a descriptive tool tip pop up: System Class Sprite (see Figure 2.3). Try dragging your mouse over other parts of your program, and you will see a few other tool tips pop up. We will explain those soon, but for now, let's explain the System Class Sprite tool tip.

Figure 2.3

Figure 2.3 A tool tip identifying System Class Sprite

A system class is a kind of object that Phrogram provides to you, and that makes it easy for your programs to do certain things. Different system classes are useful for different things. Sprites are particularly useful for displaying graphical objects on the screen, such as UFOs or kittens or cars or anything else you might like to include in your game. Another system class that will we show you how to use soon is the sound system class. We are sure you can guess the kinds of things the sound system class lets your program do!

The next instruction, on line 6, tells Phrogram to fetch a file called "ufo.gif" and use the picture in that file to display myUFO:

myUFO.Load( "UFO.GIF" )

Where does Phrogram find this file? Phrogram automatically finds files in the Media Files subfolders under the My Phrogram Files folder. There are separate subfolders there for images and for sounds. If you want to use your own images or sounds, just drop them into the appropriate folder, and then you can use them by name just like you used "ufo.gif". Phrogram will also automatically find a media file if it is stored in the same folder where you save your program.

The rules about using Load are not difficult, but they are exact! Load requires only one "value" for it to work: It requires the name of the image file Phrogram will use for this sprite—in our case, "ufo.gif". This value must be surrounded by double quotation marks, as shown. Here are two examples that show incorrect ways of telling Phrogram to load this sprite's image. Let us repeat: These two instructions will not work because they do not follow Phrogram's rules about using Load(). Can you figure out what to change to make these work?

myUFO.Load( 'UFO.GIF' )
myUFO.Load( UFO.GIF )

In order to explain the next instruction in our program, on line 7, we will bring up a very important new topic, your computer's coordinate system:

myUFO.MoveTo( 50, 50 )
  • + Share This
  • 🔖 Save To Your Account