lack of control in how often to redraw screen...?

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
fattymc03
Posts: 18
Joined: Sat Feb 11, 2006 12:22 am

lack of control in how often to redraw screen...?

Post by fattymc03 »

In my game, i'm moving the background (like a scrolling background 2d game). In my main WHILE DO loop, I just shift the background 1 pixel over. I have no timer when to do this, so it just does it everytime it goes through the loop. How can I actually control the speed and make it move faster, because right now, its moving at 1 pixel per loop pass and it doesnt really move fast. If i make it move more than 1 pixel it would look jumpy. I just find it strange that I cannot move the background faster (but still smoothly). Any ideas.
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

Even 2 pixels, still jumpy to naked eyes??

Maybe a better idea... move one pixel during even loop and two pixels during odd loop.
Geo Massar
Retired Engineer
fattymc03
Posts: 18
Joined: Sat Feb 11, 2006 12:22 am

Post by fattymc03 »

I guess your right, its not noticable. I guess the real issue is the background isnt moving in a separate thread and i'm afraid that once there is more code and calculations within that loop, it will move the background at a slower speed. It's like the speed of the background moving is based on how much processing is being done in the loop. Or am I wrong..?
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

Good question, indeed. Others who might have experienced with background moving would answer better.

Suggest using a timer to time the amout of time required to move the background.
Geo Massar
Retired Engineer
fattymc03
Posts: 18
Joined: Sat Feb 11, 2006 12:22 am

Post by fattymc03 »

Yeah, I tried a timer, but that would only be used if I wanted it to move slower. Like right now, there is no timer and it just moves every time through the loop -- so thats like the maximum speed it moves (by moving 1 pixel) in the current loop. So adding a timer would only be useful if I wanted to slow it down.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

are you using a backbuffer?

greets
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
fattymc03
Posts: 18
Joined: Sat Feb 11, 2006 12:22 am

Post by fattymc03 »

doesn't it automatically draw to the back buffer (with screen:blit()) until you say screen:flip()?
liquidjin
Posts: 12
Joined: Sun Feb 19, 2006 5:57 pm

Post by liquidjin »

fattymc03 wrote:doesn't it automatically draw to the back buffer (with screen:blit()) until you say screen:flip()?

The answer to your question is yes.

However, check out the last section of the tutorial on the Wiki. You want to blit smaller images onto a larger offscreen image and then blit that larger image to the screen to preserve the native framerate.
fattymc03
Posts: 18
Joined: Sat Feb 11, 2006 12:22 am

Post by fattymc03 »

thank you! is there a way to tell at what frame rate my program is running at?
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

i could support a FPS function, but i am not able to compile luaplayer...
freetype won't install correct.

let me know if someone is able then ill send the function to add

greets
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

ok, i found the bug, and solved it.
next problem is that there seems to be an 'mistake' (guess it is one as the source of luaplayer on svn does not compile without beeing modyfied.)

so i had to remove the SIO stuff (sorry)
i added the FPS functions (did not test em!!!)

just call system.initFPS() when you start your script
then call system.getFPS() when you want the current FPS value.
(usually every iteration)

here is the download for luaplayer with FPS:
download here

greets
lumo
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
liquidjin
Posts: 12
Joined: Sun Feb 19, 2006 5:57 pm

Post by liquidjin »

fattymc03 wrote:thank you! is there a way to tell at what frame rate my program is running at?
I can't give you exact code, because I'm not too familiar with working on the PSP yet. However in the beginning of your main loop you would want to do the following
{
- if FPS counter >= 10 (to minimize spiking only check every 10 frames)
-check difference between oldtime (milliseconds) and newly acquired time(milliseconds)
- FPS = 10000/difference(milliseconds)
- set FPS counter = 0
END
- if FPS counter = 0
- oldtime = current time (milliseconds)
END
-increment FPS counter

... your code ...
}

Hope this helps,

LiquidJin
fattymc03
Posts: 18
Joined: Sat Feb 11, 2006 12:22 am

Post by fattymc03 »

thanks for all the help on this subject, everything has been helpful.. i do have a follup question to my original. it's hard for me to explain this but i'll try..

So, I'm trying to make a 2d side scrolling plane shooter game. In the main loop, it redraws the screen every pass through with updated positions of objects on the screen. The issue comes with how to show different speeds of different objects. If I want to shoot a straight bullet and make it look like it's traveling faster, the only way I could figure was to make it move in the X direction more than 1, so if I added 5 every pass through the loop it would move faster. That's fine. But the issue comes if, for example I wanted to make a bullet travel in an arc path. If I draw it at every X point, it will travel along that path fine, but it would be slow. If I try and speed it up and use the same method as mentioned before, it doesn't really follow the path because it would be jumping to far into the path (like at X = 1, X = 6, X = 11, etc) so it would look jumpy and not a smooth path. So what I really want to be able to do is make it draw that faster, but it doesnt seem like that is even possible because I'm already drawing to the screen at the max speed it seems if I don't even have a timer and I'm redrawing every time through the loop. Am I doing something wrong or is this a limitation w/o having multiple threads. Please help. Thanks.!
liquidjin
Posts: 12
Joined: Sun Feb 19, 2006 5:57 pm

Post by liquidjin »

You're on the right track. Speed is just a measure of distance/time. So if you want to make something move faster than another object, you would increase the distance it moves in the same time period.

However, when you are dealing with arcs I would advise you to use parametric equations to find your exact coordinates. Do a search for these. This should solve your problem when it comes to the object moving off the path and causing jumps.
fattymc03 wrote:thanks for all the help on this subject, everything has been helpful.. i do have a follup question to my original. it's hard for me to explain this but i'll try..

So, I'm trying to make a 2d side scrolling plane shooter game. In the main loop, it redraws the screen every pass through with updated positions of objects on the screen. The issue comes with how to show different speeds of different objects. If I want to shoot a straight bullet and make it look like it's traveling faster, the only way I could figure was to make it move in the X direction more than 1, so if I added 5 every pass through the loop it would move faster. That's fine. But the issue comes if, for example I wanted to make a bullet travel in an arc path. If I draw it at every X point, it will travel along that path fine, but it would be slow. If I try and speed it up and use the same method as mentioned before, it doesn't really follow the path because it would be jumping to far into the path (like at X = 1, X = 6, X = 11, etc) so it would look jumpy and not a smooth path. So what I really want to be able to do is make it draw that faster, but it doesnt seem like that is even possible because I'm already drawing to the screen at the max speed it seems if I don't even have a timer and I'm redrawing every time through the loop. Am I doing something wrong or is this a limitation w/o having multiple threads. Please help. Thanks.!
Post Reply