Yesterday, I discovered a serious flaw in the design of Bullfrog.
I’ve been developing this game on a PowerMac Dual 2GHz G5 with 1 GB RAM. The game was designed to run at approximately 60 frames per second. The animation was smooth and all the game objects moved at their correct speeds.
Last night, I decided to move my development over to my aging PowerBook 800 MHz G4 with 1 GB RAM so I could work on my code while watching the World Series on my couch.
Boy, what a wake up call!
Everything crawled on the screen. My frame rate dropped to about 30 frames per second and the whole thing became unplayable.
So, in comes the major refactoring task in order to support time-based animation and movement. After a long night, it all seems to be working now.
I keep track of time elapsed between frames and then calculate the percentage difference from the 60 frames per second. Then take that percentage and multiply it against the movement constants for each game object. This seems to take care of all the problems — though I probably need to test it out on some different processors when I get the chance.
Comments
4 responses to “Time-based Animation”
I think I need to work on my similar code. The sprite library I use works with integer positions, but I need to calculate the the movement in double values for the precision. Otherwise, the objects would be stuck in one spot due to the loss in precision.
The problem is that I notice the movement jerks every so often, and I think it is because it adds or subtracts an extra pixel every so often. I could be wrong. Are you using floating points for your positioning and movement as well?
I’m using floating points for positioning. The
NSPoint
object in Cocoa tracks (x,y) coordinates asfloat
data types.Jon, I use a 600MHz iBook with 512MB of RAM. If you ever want to get some results from a rapidly aging system, you now have my email address. I’d love to help you with any benchmarking you might want to do, etc.
Thanks Rob, I may take you up on that offer. I’ll let you know when I’m ready for my first round of testing. Hopefully, it’ll be sooner than later.