Spritelibs and timers

Published March 31, 1998
Advertisement
First off, I discovered that SpriteLib has moved here. The author has dropped the weird licensing stuff. You just need to put your free SpriteLib reg # somewhere in your app (like the "about" box). There's now no reason not to have this thing.

I made a long-overdue change to my timer code. In an average game, I would start 2 or 3 timers, using my GameTimer class (basically a wrapper for the Windows Timer stuff). Usually the game had a GameTimer that would drive the sprites. I had a completely separate GameTimer handling updates to eye candy (little short-lived graphical bits that aren't interactive, like explosions, sparkles, etc). Problem was, I was getting some ugly race conditions and had to add some unwanted wait-for-sync routines.

To fix the problem once and for all, there is now a single "master timer". Creating a new GameTimer object simply hooks into it. Whenever the master timer ticks, it calls all hooked objects. When nothing's hooked, the timer is quietly killed. The change seems to have sped things up a bit and has gotten rid of the need for any wait-for-sync nonsense.

I also added a new attribute to the Sprite class, Touchable. Early on, I had plenty of cool routines for collision-detection, returning all sprites that were touching a given one. Unfortunately, things got ugly with the advent of eye-candy. At some points, there can be lots of eye-candy bits on the screen (especially Zap Pod!, which has explosions everywhere). You could no longer pass an array to the routine that returned all touching sprites, as you didn't know how large to make the array. Sifting through tons of useless sprites to find your enemy was also a pain, so I added a Touchable attribute. If it's set to FALSE, the default, the sprite will not report itself as touching a given sprite. This way, stuff can be dancing all about the screen, but the important game sprites (the ships and bullets) will ignore 'em.

Zap Pod! is basically done. I put in the bonus ship/bomb code and the preferences dialog box. If you want a screen shot, go to the Code Zone site.
Previous Entry No Code Today
Next Entry No Ferrari for me
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement