DartGameDevs

Bleeding edge tutorials and news for game developers working with Dart

New game_loop Release

Today I released a new release of Dart’s game_loop library. Version: 0.6.0. Since January some bug fixes have landed and some important breaking changes have been added to the library. Read on for details.

Super Mario

Split of game logic update and game drawing

The correct usage of game_loop requires you to decouple your drawing code from your game update code:

1
2
3
gameLoop.onUpdate = ((gameLoop) {
    // Game update logic here.
});
1
2
3
gameLoop.onRender = ((gameLoop) {
    // Game drawing here.
});

The library will do the right thing and call onUpdate when it’s time to update the game world and onRender when it’s time to draw it. game_loop calls these functions at the right time letting you focus on your game and not the browser.

Controlling how frequently your game logic updates

How frequently onUpdate is called can be controlled with the updateTimeStep member variable. By default it is 15 milliseconds.

Time source

Absolute Time

There are a two sources of absolute time in game_loop. The first is time which gives you the current time of the computer. For game logic time see gameTime which is kept in sync with any game_loop timers. In case it’s not obvious, you should be using gameTime almost all the time.

Delta Time

There are two sources of delta time in game_loop. The first is dt which is always the same as updateTimeStep, that is, the logical game time change since the last call to update. There is also requestAnimationFrameTime which is the delta between requestAnimationFrame callbacks from the browser. Again, you should almost always be using dt which is linked to gameTime.

Pub and Import

If you’re using pub, just run pub update and you’ll be good. If you aren’t using pub, start!

1
2
dependencies:
  game_loop: any
1
import 'package:game_loop/game_loop.dart'

Be sure to checkout the GitHub project and read the docs here.