DSLua Community
Welcome, Guest. Please login or register.
May 21, 2012, 08:15:35 PM
1371 Posts in 262 Topics by 33109 Members
Latest Member: Limewire Download
DSLua Community  |  DSLua - Best scripting language for Nintendo DS  |  Need Help?  |  When to use Screen.WaitForVBL() « previous next »
Pages: [1]
Author Topic: When to use Screen.WaitForVBL()  (Read 1284 times)
sylus101
Waxing Crescent
**
Posts: 68



« on: May 16, 2007, 12:14:44 AM »

I understand it's good to use that function to avoid certain screen glitches. Is there an exact science as to when to use it?
Logged
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #1 on: May 16, 2007, 12:52:53 AM »

I've never really used it because I always assumed DSLua called the PAlib function of it for you. But I could be wrong I guess.

In the PAlib examples there is always an "infinite loop" that the whole program runs in. At the top of this loop they put the wait for V-blank function.

The only places I've used it is for delays. A V-blank is always 1/60 of a second on the DS hardware (not sure about emulator.) So if I want a delay of 2 seconds I do this:

for i = 1, 60*2 do Screen.WaitForVBL() end
Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #2 on: May 16, 2007, 07:18:44 AM »

There are only two uses for the WaitForVBL function:

1) As jeremysr already said, for delays (there are 60 of them per second on a DS)

2) If you wait for a VBL before loading a large number of sprites consecutively, they are far less likely to 'skip-load' -- in other words, having slight delays between each sprite or two.

Other than that, I don't think it has any real uses.  Huh
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
sylus101
Waxing Crescent
**
Posts: 68



« Reply #3 on: May 16, 2007, 11:44:37 AM »

Okay, sounds good.

Here's a couple of functions I like to use for delays:

function vbwait_sec(t)
  t = t * 60
  for delay=1,t do
    Screen.WaitForVBL()
  end
end

function vbwait(t)
  for delay=1,t do
    Screen.WaitForVBL()
  end
end
Logged
Pages: [1]
« previous next »
    Jump to: