Hello World! Second Edition: Computer Programming for Kids and Other Beginners by Warren Sande Carter Sande

Hello World! Second Edition: Computer Programming for Kids and Other Beginners by Warren Sande Carter Sande

Author:Warren Sande Carter Sande
Language: eng
Format: epub, mobi
Publisher: Manning Publications


Scaling the frame rate

If you want to be really sure your animation runs at the same speed on every machine, there’s a trick you can do with clock.tick() and clock.get_fps(). Because you know the speed you want to run at and the speed you’re actually running at, you can adjust, or scale, the speed of your animation according to the speed of the machine.

For example, let’s say you have clock.tick(30), which means you’re trying to run at 30 fps. If you use clock.get_fps() and find you’re only getting 20 fps, you know that objects on the screen are moving slower than you’d like. Because you’re getting fewer frames per second, you have to move your objects farther in each frame to make them appear to move at the correct speed. You’ll probably have a variable (or attribute) called speed for your moving objects, which tells them how far to move in each frame. You just need to increase speed to make up for a slower machine.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.