Racket 的 Big Bang 框架——使用滴答率使游戏运行得更快? [英] Racket's Big Bang framework - making a game go faster using tick rate?

查看:34
本文介绍了Racket 的 Big Bang 框架——使用滴答率使游戏运行得更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此在 Big Bang 框架中,您可以指定滴答率:

So in the Big Bang framework you can specify a tick rate:

(on-tick-handler tick-rate)

(on-tick tick-handler tick-rate)

此滴答率值仅在我相信时评估一次(有一个 类似的问题在这里是这样陈述的).

This tick-rate value is evaluated only once I believe (there is a similar question on here where this is stated as so).

如果是这种情况,您将如何编写一款游戏(例如俄罗斯方块),您希望随着时间的推移形状以更快的速度下降?目前我已经在蜱处理程序上发生了形状下降.如果滴答率发生变化,下降会更频繁地发生.事实上,如果没有该功能,我无法弄清楚如何实现这一点.有什么线索吗?

If that's the case, how would one go about writing a game (such as Tetris) where you want the shape to drop down at a quicker rate as time goes by? I've got the shape-drop occurring on the tick-handler at present. If the tick-rate changed, the drop would occur more frequently. As it is, I can't figure out how to make this happen without that feature. Any clues?

推荐答案

将滴答频率设置为您需要的最快速度.做一个滴答计数器.在你的滴答处理程序中有类似的东西:

Set the tickrate to the fastest rate you need. Make a tick counter. In you tick-handler have something like:

 (define rate 4)
 (cond
   [(= (remainder tick-counter rate) 0)   do-the-same-as-before]
   [else                                  do-nothing-but-increment-counter])

当 rate 为 4 时,您只会在每第四个刻度激活您的刻度处理程序.如果您将 rate 更改为 2,则速度将提高两倍.而当 rate 为 1 时,您将获得最快的速度.

When rate is 4, you will only activate your tick handler for every fourth tick. If you change rate to, say 2, you the speed is twice as fast. And when rate is 1, you will get the fastest speed.

这篇关于Racket 的 Big Bang 框架——使用滴答率使游戏运行得更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆