Hi to all.
I have a very simple questions. I have a game with a player that is
controlled with the keyboard. I want the sprite to move to the same
speed on any hardware, not depending of frames displayed or other
things. Mostly because the game may have network support, and so
everything needs to go to the same speed.
Oooh, this one’s not very simple at all, actually… Well, the
theory is actually pretty simple, but it’s not quite that easy in
real life, at least not if you also want optimal animation quality
and accurate (maybe even 100% repeatable) game logic. You will want
both for any serious gaming.
Would it be a good idea to have a function ran every 20ms (for
example) that moves the sprite according to what it needs to (the
event are saved before, like need to be moved UP, DOWN, LEFT,
RIGHT, etc), so we are sure it does move at the same speed
Basically, yes - but you can’t actually implement it that way, unless
you’re fine with capping the animation frame rate and/or messing with
thread safe interaction between the game logic and the graphics
Any hint, or better, url about this concern is appreciated
I recently hacked a playable example, demonstrating (among other
things) my favourite approach: Fixed Logic Frame Rate +
Interpolation. This design lets you get away with a plain, fixed
logic frame rate (as it was done in the days of PAL/NTSC based
systems) and a single thread for the whole game, and still get the
maximum possible rendering/animation frame rate on any hardware.
The same approach is also used in the game Kobo Deluxe, which was
originally (XKobo) a fixed frame rate game:
I suggest you look at the Pig first, though. Kobo Deluxe is layers and
layers of (mostly) C++ code, and it was hacked to be played - not
analyzed. Don’t mess with it unless you’re interested in the game
Meanwhile, Fixed Rate Pig was hacked specifically to be a minimal but
complete example of some techniques that people ask a lot about
around here. (Fixed logic frame rate, motion interpolation, tiled
backgrounds, sprite animation, smart updating with pageflipping,
basic platform game logic etc.) It even comes with a document
describing what most of that cryptic code is all about.
//David Olofson - Programmer, Composer, Open Source Advocate
.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
— http://olofson.net — http://www.reologica.se —On Wednesday 24 March 2004 18.16, Fabien Penso wrote: