Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

#1 2015-08-18 03:09:23

ek82
Member
Registered: 2015-08-12
Posts: 10

Best place to increment your timers.

So I have some counter/timer variables that I increment and check against a delay to control logic, such as updating some enemy sprite positions. Originally I just kept incrementing my timer in the main game loop and checked against a delay value. I figured once I had the right delay I wanted, the incrementing speed would more or less be the same across all Game boys?

Although this was working OK, it seemed a little dirty so I moved my timer incrementing line into my VBL interrupt. I'm using that interrupt any way, so I figured I would put it there. This also seems to work OK, I just had to adjust my delay value since it doesn't increment as fast.

But now I see there is a timer interrupt on its own. Should I only use that interrupt for timing? Or are my other two solutions also acceptable?

Thanks

Last edited by ek82 (2015-08-18 03:10:05)

Offline

 

#2 2015-08-18 09:33:22

Scazon
Member
From: Boston, MA
Registered: 2015-06-14
Posts: 24
Website

Re: Best place to increment your timers.

It depends on what kind of game it is and what you use the timer for. Some of my early games just use the timer for animation purposes only (all sprites animate at around 4 frames/sec, all in sync), so I put the timer in a tick() function that gets called every main loop with a delay.

I also have a music based game, where keeping time is very important, so I put it in the timer interrupt. I havent used the vbl interrupt for timers yet, but I imagine it would work the same, the only benefit is that the timer interrupt would be more reliable in terms of timing (I think). Also, you can change some of the timer registers so that the interrupt happens at specific intervals, instead of relying on vblank.

Last edited by Scazon (2015-08-18 09:35:04)

Offline

 

#3 2015-08-22 18:26:51

ek82
Member
Registered: 2015-08-12
Posts: 10

Re: Best place to increment your timers.

Thanks for the details Scazon. I went ahead and used the timer interrupt. Works great and I like how I can change the interrupt time.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson