pygame 中的步行周期和计时

发布于 2024-08-09 12:07:27 字数 381 浏览 4 评论 0原文

我的游戏中运行着 pygame.Timer,每秒调用绘制函数 32 次。绘图方法获取屏幕上所有元素的位置并相应地传输它们。然而,我希望主角走动的速度比其他物体的移动速度慢。

我应该专门为其设置一个计时器,还是应该将相同的帧传输几次?有没有更好的办法呢?朝着正确的方向推动会很棒:)

(如果有人感兴趣,这里是当前控制将哪些帧发送到绘图的代码:http://github.com/kallepersson/subterranean-ng/blob/master/Player.py#L88)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几味少女 2024-08-16 12:07:27

您的步行周期帧(像所有运动一样)应该是绝对时间的函数,而不是帧计数的函数。例如:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文