Evaluating the Role of Sprites in Games


Evaluating the Role of Sprites in Games

Sprites are incredibly important in virtually all two-dimensional games because they provide a simple, yet effective means of conveying movement while also allowing objects to interact with one another. By modeling the objects in a game as sprites, you can create some surprisingly interesting games in which the objects interact with each other in different ways. The simplest example of a sprite used in a game is Pong, which involves a total of three sprites: the ball and the two paddles (vertical bars) along each side of the screen. All these objects must be modeled as sprites because they all move and interact with each other. The ball floats around on its own and bounces off the paddles, which are controlled by each of the two players.

As games get more complex, the role of sprites changes slightly, but their importance only increases . For example, a tank battle game would obviously use sprites to model the tanks and bullets that they shoot at each other. However, you could also use sprites to represent stationary objects such as walls and buildings . Even though the stationary objects don't move, they benefit from being modeled as sprites because you can detect a collision between them and a tank and limit the tank's movement accordingly. Similarly, if a bullet strikes a building, you would want to kill it or make it ricochet off the building at an angle; modeling the building as a sprite allows you to detect the bullet collision and respond accordingly .

It's important to point out that sprites are closely linked with bitmap images. Although it's certainly possible to create a sprite that is drawn out of graphics primitives, sprites are typically based on bitmap images. So, in the example of the tank game, each type of sprite corresponds to a bitmap image that is used to draw the sprite on the screen. The sprite's job is to keep track of the position, velocity, Z-order (depth), and visibility of a tank, whereas the bitmap keeps track of what the tank actually looks like. From a programming perspective, the Bitmap class is responsible for the appearance of a tank, whereas the Sprite class is responsible for how the tank moves and behaves with other objects.

Speaking of the Sprite class, there is no such existing class for us to borrow and use. Apparently, sprites represent a unique enough programming challenge that few standard programming libraries, such as Win32, support them directly. For this reason, you'll have to create your own Sprite class. The remainder of this hour focuses on the design, development, and testing of this class.



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