Sprite

What Is It?

The sprite player displays images that come from GIF files or JPEG files. A sprite can display multiple images, flipping between the images in response to a message, with the passage of time, or under control of a path animation.

A sprite player is visible and playable.

Why Use it?

Use a sprite player to animate a series of bitmaps.

How to Create It

To create a sprite player, go to the Players toolbar and click on Sprite. A new sprite player appears in the Players window, already selected. You will now:

  1. Select the sprite images.
  2. Set the sprite properties.
  3. Specify the trigger for flipping the sprite image.
  4. Play the sprite.

Selecting Sprite Images

NOTE: For most sprites, the order in which you specify the sprite's images is important. First-time users should consider setting the properties first and then selecting the images.

To preview and choose GIF and JPEG files that the sprite will display:

  1. Click on the Data button, then locate your graphics folder in the Open window.
  2. Select a file name to view its image on the right.
  3. To select a file, click on the plus (+) sign under category Bitmap.
  4. Click Done to close the Open window.

The sprite player in the Players window now displays the image that you chose. If you chose multiple images or an animated GIF, go to the Control toolbar and click on the Flip Forward and Flip Back buttons to view them.

Setting Sprite Properties

To set the properties for the sprite, go to the Player toolbar and click on the Properties button. In the Property sheet, set the sprite properties as follows:

Property Purpose
SMOOTH To smooth the edges of the image.
SCALETOFIT To automatically resize and reshape the image to fit into the RECT.
BLEND To blend the sprite player with the image underneath it. The value 100 keeps the image totally opaque; 0 makes it totally transparent.
PRELOAD To load all the data for the sprite before the mbedlet starts.
FLIPTYPE To specify the trigger for changing a sprite's image. The trigger can be based on time, distance, or direction.

A sprite player also has playable properties and visible properties.

Controlling Movement

A sprite can flip its images over time, by distance, or according to direction.

Flipping Images Over Time

To flip images based on elapsed time, set FLIPTYPE to TIME.

Enter a time value, in milliseconds, for the FLIPINTERVAL property. When the specified number of milliseconds passes, the sprite changes its image. (The sprite below flips images every .1 second because its FLIPINTERVAL property is set to 100 milliseconds).

The FLIPINDEX property specifies which image in your list of bitmaps will be the first image displayed for the sprite.

Flipping Images By Distance

To flip images based on distance, set FLIPTYPE to DISTANCE. Set the FLIPINDEX property to the first image you want to display.

The sprite automatically flips its image as it reaches distances along a curve, depending on the number of images it has. For example, if a sprite has four images, it flips four times along a distance:

Flipping Images According to Direction

To flip images based on direction, set FLIPTYPE to DIRECTION. Set the FLIPINDEX property to the first image you want to display.

The sprite image flips depending on its direction of motion, measured as an angle. Consider the angles as points on a clock, where:

By flipping multiple images based on direction, you can display a pointing meter, a car driving back and forth, or other objects whose image changes in a directional mode. A meter, for example, might consist of a needle sprite moving in a half-circle, 180 degrees, between 9:00 and 3:00. As the needle moves, the sprite flips to various graphics showing the needle pointing at different angles.

As an example, suppose you want to show an object travelling along a circular clockwise path. You could create twelve images, one for each 30 degrees, equivalent to the hours on a clock. The first image defined as data for the sprite should be the image of the object displayed at zero degrees, or the 12:00 position of the path. The next image defined as data should be the image of the object displayed at 30 degrees, or the 1:00 position of the path, and so on.

The STARTANGLE property specifies the starting image's angle relative to zero degrees or 12:00, measuring clockwise.

The TOTALANGLE property specifies the range of motion. For example, if the sprite moves only within 180 degrees, or between 9:00 and 3:00, specify 180.

If the image displayed at 12:00 on the path should change according to its direction of movement, set the PARALLEL property. The PARALLEL property indicates that the axis of symmetry for the sprite moves along the path.

An example of a sprite that would use the PARALLEL property is a car image, driving forward and back. At any point, the sprite uses a different image depending on the car's direction. An example of a sprite that would not use the PARALLEL property is the hand of a clock (assuming that the clock could go backward in time). The clock hand looks the same at 12:00 whether it is moving clockwise or counter-clockwise.

Playing a Sprite

There are several ways to cause a sprite to begin playing. For the example below, we created a handler on the mbedlet that tells the Moon sprite to play as soon as the mbedlet begins running. You could also put a handler directly on the sprite; for instance, a handler that fires when the user's mouse goes over the sprite. When the sprite receives the MOUSEENTER message, it starts to play, but when it receives the MOUSELEAVE it stops.

But suppose you wanted to control the time between each flip of the sprite (for example, the first, second, and third images flip every .5 seconds, but the fourth, fifth, sixth, and seventh images flip every 2 seconds). For this type of control you would use a score player. At each point in time you wanted the sprite to flip images, you would put a Flip command.



Previous Page Next Page