Framerate Adjustment (Smash Hit)¶
- knGetDeviceHz()¶
Get the refresh rate of the device’s default display in hertz.
Added in version 13.
-
knSetFrameRate([
frameRate, [sleepTime]])¶ Set the target frame rate of the game and adjust the simulation time step to compensate.
With no arguments,
knSetFrameRate()will set the game to run at the device’s refresh rate, enabling the game to run on >60Hz devices at full framerate without much hard work. You might need to update timers to respect the new framerate (e.g. some bosses assume 60 ticks per second).If you just want to support >60Hz devices, simply have:
function load() -- ... knSetFrameRate() -- ... end
in your
menu/main.lua.With only the first argument,
knSetFrameRate(fps)will set the game to target exactlyfpsframes per second, settingsleeptimeto be1/fps. On devices whereknGetDeviceHz() < fps, the game will run slower in some places.With both arguments,
knSetFrameRate(fps, sleeptime)will set the game to run as if it were targeting exactlyfpsframes per second, with the caveat that it will only sleep forsleeptimeseconds if the frame finishes rendering early AND the display takes less thansleeptimeseconds to update.Please note that
knSetFrameRate(60)is NOT the same as the default, due to the sleepTime being different. If you want to go back to defaults dynamically, useknSetFrameRate(60, 0.015).