Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
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.
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.