O'Reilly logo

Learning Dart - Second Edition by Ivo Balbaert

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Animating a game

We people like motion in games and a movie is nothing but a quick succession of image frames. So, we need to be able to redraw our screen periodically to get this effect; with Dart screen frame rates of 60 fps or higher, this becomes possible. A certain time interval is represented in Dart as an object of the Duration type. To do something periodically in Dart, we use the Timer class from the dart:async library and its periodic method. To execute a moveBall()function at every INTERVAL ms (you could call it a periodic event), use the following method:

new Timer.periodic( const Duration(milliseconds: INTERVAL),(t) => moveBall()  );

The first parameter is the time period, the second is the callback function that has to be periodically ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required