//Game loop func (game *Game) Run() { defer game.Exit() if game.initFun == nil { fmt.Println("Go2D Warning: No init function set!") } if game.updateFun == nil { fmt.Println("Go2D Warning: No update function set!") } if game.drawFun == nil { fmt.Println("Go2D Warning: No draw function set!") } //Initialize the game game.initialize() var dt, old_t, now_t uint32 = 0, 0, 0 for game.running { //Check for events and handle them for { event, present := sdl.PollEvent() if present { EventHandler(event) } else { break } } //Calculate time delta now_t = sdl.GetTicks() dt = now_t - old_t old_t = now_t //Update game.update(dt) //Draw game.draw() //Give the CPU some time to do other stuff sdl.Delay(1) } }
func GetTicks() uint32 { return sdl.GetTicks() }