Previous: , Up: Booting   [Contents][Index]


4.1.2 The Game Loop

Scheme Variable: draw-hook

This hook is run every time the game loop wants to render. Procedures added to this hook should accept two arguments: dt, the time in seconds since the last render call; and alpha, a number in the range [0,1] that indicates how far in between two discrete updates of the game state the loop is in. The alpha value is important for smoothing animated values to avoid the “temporal aliasing” effect that causes choppy looking animations.

Scheme Variable: after-game-loop-error-hook

This hook is run every time the game loop catches an error. Procedures added to this hook should accept no arguments.

Scheme Procedure: run-game-loop [#:frame-rate] [#:tick-rate] [#:max-ticks-per-frame]

Start the game loop. frame-rate specifies the optimal number of frames to draw per second. tick-rate specifies the optimal game logic updates per second. Both frame-rate and tick-rate are 60 by default. max-ticks-per-frame is the maximum number of times the game loop will update game state in a single frame. When this upper bound is reached due to poor performance, the game will start to slow down instead of becoming completely unresponsive and possibly crashing.

Scheme Procedure: stop-game-loop

Abort the game loop.