问题
So in the Big Bang framework you can specify a 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?
回答1:
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])
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.
来源:https://stackoverflow.com/questions/44356735/rackets-big-bang-framework-making-a-game-go-faster-using-tick-rate