I have a question regarding how to use screen:flip() and screen.waitVblankStart(). From what I have read you should issue the screen.waitVblankStart() before you do a screen:flip() , to wait for the start of the vblank etc. So based on that the following should work:
screen:print(10,10,"test",Color.new(255,255,255))
screen.waitVblankStart()
screen:flip()
pad = Controls.read()
while not pad:start() do
pad = Controls.read()
end
but it doesn't display anything. However if I do the following it does work:
screen:print(10,10,"test",Color.new(255,255,255))
screen:flip()
screen.waitVblankStart()
pad = Controls.read()
while not pad:start() do
pad = Controls.read()
end
Why ? This behaviour does not seem to backup the definition of waitVblankStart. The only thing I can think is that if the text is not drawn by the time the code hits the do loop then the screen is effectively frozen while the do loop is executing. Can somebody shed some light on this for me ?
The screen.waitVblankStart() waits until the screen refreshes so, when you call the function it waits until the screen refreshes before doing anything. You also dont need to use that function if you arent going to be refreshing the screen, example reactive scripts, do not require this since screen.waitVblankStart() slows it down, however
creating animations and things like that need to have screen.waitVblankStart() . If that makes sense
screen:print(10,10,"test",Color.new(255,255,255))
screen.flip()
screen.waitVblankStart()
pad = Controls.read()
while not pad:start() do
pad = Controls.read()
end
And it works, with Lua Player Windows, Lua Player 0.19 and even with the new Lua Player 0.20 with Lua 5.1 support (not yet released).
I am still cutting my first teeth with Lua and from reading some of the documentation it suggested that the waitVblankStart() should come before the flip (I see a lot of programs that use it this way). But from what you guys are saying it should always come after the flip, it that correct ?
JC wrote:from reading some of the documentation it suggested that the waitVblankStart() should come before the flip (I see a lot of programs that use it this way). But from what you guys are saying it should always come after the flip, it that correct ?
As romero126 said: You don't need it for your example.
But you should first wait for the vblank, then switch the buffers to avoid flickering and other effects. As I explained: You are drawing to the offscreen buffer (an image with the size of your PSP screen, but invisible) and with "flip" the offscreen buffer will be displayed. But the PSP re-displays the current buffer 60 times per second, line-by-line, so you have to wait for the vblank (this is the time when after the last line is displayed and before the displaying the first again) to avoid switching in the middle of the process. This is important for animations: Imagine you move something on the offscreen, but on the onscreen buffer it is in the old position. If you switch the buffer when the PSP has displayed the first half of the onscreen, then for the second half the offscreen is displayed and the upper half of your moving object may be some pixels behind the lower half.
romero126 wrote:lol shine i love your explinations their great. any idea when you could allow loading images and sounds from variables without saving them to a file?
why would you want that? in most cases you need the images again.
and if you don't need them anymore, give all those images/sounds the name dummy_image(_sound) and so they're overwritten the next time