game_loop 0.9.4

  • Readme
  • Changelog
  • Installing
  • 0

game_loop #

==============

Introduction #

All games require a main loop to drive the game forward. This main loop is responsible for processing inputs from keyboards, mice, gamepads, and time. Also, the main loop manages browser state, e.g., pointer lock and fullscreen. Finally, the main loop calls the game specific update routine. The game_loop library provides a main loop designed for games along with a powerful input subsystem.

If you are familiar with GLUT, game_loop provides that and more.

Features #

  • Main loop optimized for games.
  • Keyboard input.
  • Mouse input.
  • Fullscreen management.
  • Pointer lock management.
  • Timers.

Why game_loop ? #

1. Focus on your game not on the browser platform. A perfect main loop requires code which properly combines input, time, display, and state management. Writing this code is tedious, error prone, and ultimately, a waste of time.

Getting Started #

1. Add the following to your project's pubspec.yaml and run pub install.

dependencies:
  game_loop:
    git: https://github.com/johnmccutchan/game_loop.git

2. Add the correct import for your project.

import 'package:game_loop/game_loop_html.dart';

OR

import 'package:game_loop/game_loop_isolate.dart';

Documentation #

API #

Reference Manual

Samples #

1. test.html

Examples #

1. Initialize a game loop:

main() {
  // Construct a game loop.
  GameLoopHtml gameLoop = new GameLoopHtml(canvasElement);
}

2. Hook your game update function up and start the main loop:

main() {
  // Construct a game loop.
  GameLoopHtml gameLoop = new GameLoopHtml(canvasElement);
  gameLoop.onUpdate = ((gameLoop) {
    // Update game logic here.
    print('${gameLoop.frame}: ${gameLoop.gameTime} [dt = ${gameLoop.dt}].');
  });
  gameLoop.start();
}

3. Hook your game render function up and start drawing:

main() {
  // Construct a game loop.
  GameLoopHtml gameLoop = new GameLoopHtml(canvasElement);
  gameLoop.onUpdate = ((gameLoop) {
    // Update game logic here.
    print('${gameLoop.frame}: ${gameLoop.gameTime} [dt = ${gameLoop.dt}].');
  });
  gameLoop.onRender = ((gameLoop) {
    // Draw game into canvasElement using WebGL or CanvasRenderingContext here.
    // The interpolation factor can be used to draw correct inter-frame
  	print('Interpolation factor: ${gameLoop.renderInterpolationFactor}');
  });
  gameLoop.start();
}

3. Add a timer to your game loop:

main() {
  // Construct a game loop.
  GameLoopHtml gameLoop = new GameLoopHtml(canvasElement);
  gameLoop.onUpdate = ((gameLoop) {
    print('${gameLoop.frame}: ${gameLoop.frameTime} [dt = ${gameLoop.dt}].');
  });
  gameLoop.start();
  // Add a timer which fires in half a second.
  var timer = gameLoop.addTimer((timer) => print('timer fired.'), 0.5);
}

0.9.4 #

  • Mark Bennett contributed stackable GameState support.
  • Fox32 contributed fixes to input processing.

0.9.3 #

  • Add a new onKeyDown handler, good for preventing default.

0.9.2 #

  • Remove dart:json import.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  game_loop: ^0.9.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:game_loop/game_loop_common.dart';
import 'package:game_loop/game_loop_html.dart';
import 'package:game_loop/game_loop_isolate.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.