Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 6. Sprites > 6.1. Sprites Overview

6.1. Sprites Overview

For sprites to be useful, you must be able to paint them, place them at specific locations in an animation, and move them from one place to another at a specified velocity. Sprites may also be called upon to perform certain activities such as falling, bouncing, flying, exploding, colliding with other sprites, etc. Table 6.1 lists Sprite properties.

Table 6.1. Sprite properties

image

The painter property refers to an object that paints sprites with a paint(sprite, context) method. The behaviors property refers to an array of objects, each of which manipulates a sprite in some manner with an execute(sprite, context, time) method. Example 6.1 shows the implementation of the Sprite object.

Sprites have two methods: paint() and update(). The update() method executes each of the sprite’s behaviors—in the order they were added to the sprite,—and paint() delegates painting to the sprite’s painter, but only if the sprite actually has a painter and the sprite is visible.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial