[SDL] How to make a game run at the same speed on any PC?
Lilith Calbridge
lilith at dcccd.edu
Sun Jul 23 18:39:16 PDT 2006
You don't have to use 500. That was just a throwaway value. Most demo
code I've seen uses a value of 30, which ostensibly gives you a frame
rate of about 30 frames a second, probably a little closer to 33. That
means the sampling rate of your events would be about fifteen times
faster than a half second interval. I haven't tried this, and probably
won't get around to it any time soon, but if you want to make your
sampling even faster than that you could probably create a shorter delay
loop inside a larger loop to do your sampling and update what's
necessary before updating the screen.
In a project I've had to put off I was thinking of looking at the
keyboard state at the moment that the decision needs to be made. I have
an object that moves towards intersections and can only move forward,
without speed change, until then . So the only thing that matters is
whether one of four possible keys is pressed at that specific time.
Maybe something like that is what you need.
Lilith
>>> On 7/23/2006 at 7:53 PM, in message <ea15lh$uag$1 at sea.gmane.org>,
leo28c at gmail.com wrote:
> Hmm... Now it all screwed up... :-(
> I think my movement mechanism is wrong... I'm doing it like, at
> SDL_KEYUP event, the movement key for that direction goes to 0...
But
> at SDL_KEYDOWN, it the variable goes to 1, so the dude's moving...
> But since this function is called only every half a second, the
movement
> is updated every half a second too! So, it starts and stops moving
half
> a second after my key presses and releases... :-(
>
> Note that I add PLR_SPEED to the player's X/Y positions in the
> update_screen function... I tried putting it in the same function as
> the event handling, but it didn't work either, it moved only every
half
> a second...
>
> Do you know how to fix this? Thanks very much! ;)
>
>
> Janne Junnila wrote:
> Peter Mackay wrote:
>> There's a great article on fixing your logic timestep here:
>> http://www.gaffer.org/articles/
>>
>> His other articles are also very good. Hope this helps,
>>
>> Peter
>>
>> "Janne Junnila" <janne.junnila at gmail.com> wrote in message
>> news:770a6dc40607230033x6df09271xbca8208b6872a5a6 at mail.gmail.com...
>>> Hi,
>>>
>>>> Anyways, I asked what update_interval was supposed to be...
Thanks!
>>> Just a constant - it's the interval between game world updates (in
ms I
>>> think).
>>> Like update_interval = 500 would make it call the update function
every
>>> 1/2 sec.
>>>
>>> The point is to make the updating function to be called on a fixed
>>> interval independent of the machine the program is run on. The
screen
>>> OTOH is updated as often as possible.
>>>
>>> - Janne Junnila
>
>> Hi,
>>
>>> Anyways, I asked what update_interval was supposed to be...
Thanks!
>>
>> Just a constant - it's the interval between game world updates (in
ms I
> think).
>> Like update_interval = 500 would make it call the update function
every 1/2
> sec.
>>
>> The point is to make the updating function to be called on a fixed
>> interval independent of the machine the program is run on. The
screen
>> OTOH is updated as often as possible.
>>
>> - Janne Junnila
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
More information about the SDL
mailing list