Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.
Allen Ray edited this page Aug 14, 2020 · 3 revisions

I wrote this to mainly clean up my gameloop. This tool provides a structure and a couple of functions to handle all of the framerate-limiting functionality.

ticker := pixelutils.NewTicker(60) // create a ticker with a target of 60 fps

// If you need to switch the target fps
ticker.SetTargetFPS(50) // fps target/limit is now 50

// Gameloop
for running {
  deltat, framerate := ticker.Tick() // calculate the frame difference and return the delta and rate

  // game logic and drawing
  ...

  // wait until at most the set frame-limit time has passed;
  //   has the potential to return immediately if logic and drawing took too long.
  ticker.Wait()
}

If you want to store previous framerates (I do for past performance monitoring), create your ticker like:

ticker := pixelutils.NewTickerV(60, 200) // store the last 200 framerates

Clone this wiki locally