QA


Q&A

Q1:

Why is the position of a sprite stored as a rectangle, as opposed to a point?

A1:

Although you might think of the position of a sprite as simply determining the location of the sprite on the game screen, it will eventually be used in other ways within the Sprite class. For example, the next hour adds collision detection capabilities to the Sprite class, which requires a sprite to support a collision rectangle. This rectangle is calculated as a percentage of the sprite's position rectangle. Of course, if a sprite's position was stored as a point, you could still come up with a position rectangle by looking at the width and height of the sprite's bitmap. However, this kind of lookup can be time-consuming when you consider that the Sprite class needs to be as efficient as possible.

Q2:

If a sprite is hidden, does it continue to be updated?

A2:

Yes. Just because a sprite is hidden from view doesn't mean that it is no longer updated. There might be situations in which you want a sprite to move around in the background unnoticed ”in which case, it should be updated while it is hidden. A good example might be a torpedo fired by a submarine in a naval battle game. You might want the torpedo sprite to be invisible until just before impact, which means that it needs to be hidden from view while it continues to be updated.



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