[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Help : speed



I want to be able to move them at different speeds.
How to do that ?
Well, you're on the right track, but instead of saying:

[Class CharacterSprite:]
def update(mscounter):
if mscounter > 500:
sprite.move()

try an approach more like:

def update(mscounter):
sprite.xpos += (sprite.pixelspeed*mscounter)
mscounter = 0

the idea is to keep track of the time elapsed and update your sprite's position based on it, but don't do it using a forced framerate. just move it the proper amount (even if it's a decimal value) and then reset your millisecond counter. that way, if the game runs on really fast hardware, it will be extremely smooth, and if the game runs on very slow hardware, it will "skip frames" automatically.

HTH,
B
--
* http://clickass.org * ICQ# 1107012 * AIM/Yahoo: theGREENzebra *
-----GEEK CODE 3.12-----
GCM/CS/IT/MU d? s: a24 C++++ UL++++ P+ L+++>$ E---- W++ N+ o K- w---$ O- M V-- PS+ PE Y+ PGP- t++(+++) 5- X R tv(+) b+(-) DI+++ D+ G++ e h++ r+(---) y+ UF*++