开发者

Walkcycles and timing in pygame

开发者 https://www.devze.com 2022-12-10 05:49 出处:网络
I have a pygame.Timer running in my game calling a draw function 32 times/second. The drawing me开发者_C百科thod gets positions from all elements on my screen and blits them accordingly. However, I wa

I have a pygame.Timer running in my game calling a draw function 32 times/second. The drawing me开发者_C百科thod 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)


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号