Assessing the Need for Sprite Management


In the previous hour , you developed a sprite class that modeled the basic physical properties of a graphical object that can move. You then created a program example called Fore that involved several golf ball sprites co-existing in the same space. Although the sprites in the Fore program were visually sharing the same space, no actual connection existed between them. Unlike the real world, the golf ball sprites were unable to collide with each other and respond accordingly ”in other words, the sprites didn't act very realistic. This limitation stems from the fact that the Sprite class alone can't account for the relationship between sprites. You need a sprite manager that is capable of overseeing a system of sprites and managing their interactions.

The idea behind a sprite manager is to group all the sprites in a system together so that they can be collectively updated and drawn. Additionally, a sprite manager must be able to compare the positions of sprites to each other and determine if any collisions have taken place. If so, the sprite manager must then somehow notify the program that the collision has occurred; in which case, the program can respond accordingly. This approach to sprite collision management is incredibly important in games, which makes the sprite manager an absolute necessity toward building games that use sprite animation.

Another benefit of a sprite manager is that it provides a means of supporting an additional bounds action, Die. The Die bounds action causes a sprite to be destroyed if it encounters a boundary. This might be useful in a shoot-em-up game in which the bullet sprites need to be killed upon hitting the edge of the game screen. It's difficult to support the Die bounds action directly in the Sprite class because the premise of the action is killing the sprite. This task is better left to an outside party whose job is to oversee all the sprites in a game ”a sprite manager.

A moment ago, I mentioned that a sprite manager makes it possible to update and draw a system of sprites collectively. This is a significant feature as you move toward creating games that rely on several sprites. For example, it could quickly become a headache trying to update, draw, and generally keep tabs on 10 or 20 sprites. The sprite manager dramatically simplifies this situation by allowing you to simply update and draw all the sprites being managed at once, regardless of how many there are.



Sams Teach Yourself Game Programming in 24 Hours
Sams Teach Yourself Game Programming in 24 Hours
ISBN: 067232461X
EAN: 2147483647
Year: 2002
Pages: 271

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net