tags:

views:

45

answers:

1

I have a pygame.Timer running in my game calling a draw function 32 times/second. The drawing method gets positions from all elements on my screen and blits them accordingly. However, I want the main character to walk around slower than other objects move.

Should I set up a timer specifically for it or should I just blit the same frames several times? Is there any better way to do it? A push in the right direction would be awesome :)

(If anyone's interested, here is the code that currently controls what frames to send to the drawing: http://github.com/kallepersson/subterranean-ng/blob/master/Player.py#L88)

+1  A: 

Your walk cycle frame (like all motion) should be a function of absolute time, not of frame count. e.g.:

def walk_frame(millis, frames_per_second, framecount, start_millis=0):
    millis_per_frame = 1000 / frames_per_second
    elapsed_millis = millis - start_millis
    total_frames = elapsed_millis / millis_per_frame
    return total_frames % framecount
Jonathan Feinberg
Thanks, but what does the millis argument represent?
kallepersson
The current time, in milliseconds.
Jonathan Feinberg