QA


Q&A

Q1:

How does the twinkle delay in the Roids example cause the twinkling of the stars to take place at different speeds?

A1:

The twinkle delay isn't a delay in a sense that it establishes a counter that counts down at a constant rate. Instead, the twinkle delay alters the probability that a star's color will be randomly changed. As an example, a twinkle rate of 1 means that a star's color will change every game cycle. Increasing the twinkle delay lessens the odds that a star's color will be changed. More specifically , a twinkle delay of 20 means that a star's color will only change an average of 1 in every 20 game cycles. Similarly, the default value of 50 for the twinkle delay in the StarryBackground class means that the color of a star is changed once in every 50 game cycles. However, because there are 100 stars in the Roids program, an average of two stars are being changed in every game cycle, which still results in a fair amount of twinkling when you consider that there are 30 game cycles per second.

Q2:

How do I create my own custom animated backgrounds?

A2:

The best way to create your own custom backgrounds is to model them after the StarryBackground class. Just copy the source code files for the StarryBackground class, and modify them to accommodate the needs of your specific background. Keep in mind that the Update() and Draw() methods are the two primary interfaces used to interact with the background from the perspective of a game. So, you'll want to make sure that all your animation code takes place in the Update() method and that the background is sufficiently painted in the Draw() method. Beyond that, it's pretty much anything goes when it comes to creating your own custom animated backgrounds!



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