game_loop 0.9.4

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 6

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';
  
Version Uploaded Documentation Archive
0.9.4 Jan 17, 2014 Go to the documentation of game_loop 0.9.4 Download game_loop 0.9.4 archive
0.9.3 Nov 8, 2013 Go to the documentation of game_loop 0.9.3 Download game_loop 0.9.3 archive
0.9.2 Oct 28, 2013 Go to the documentation of game_loop 0.9.2 Download game_loop 0.9.2 archive
0.9.1 Oct 10, 2013 Go to the documentation of game_loop 0.9.1 Download game_loop 0.9.1 archive
0.9.0 May 26, 2013 Go to the documentation of game_loop 0.9.0 Download game_loop 0.9.0 archive
0.8.0 Apr 26, 2013 Go to the documentation of game_loop 0.8.0 Download game_loop 0.8.0 archive
0.7.1 Mar 9, 2013 Go to the documentation of game_loop 0.7.1 Download game_loop 0.7.1 archive
0.7.0 Feb 25, 2013 Go to the documentation of game_loop 0.7.0 Download game_loop 0.7.0 archive
0.6.0 Feb 20, 2013 Go to the documentation of game_loop 0.6.0 Download game_loop 0.6.0 archive
0.5.0 Jan 29, 2013 Go to the documentation of game_loop 0.5.0 Download game_loop 0.5.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
13
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]
6
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.

Health issues and suggestions

Fix lib/src/game_loop_html/game_loop_html.dart. (-25 points)

Analysis of lib/src/game_loop_html/game_loop_html.dart failed with 1 error:

line 398 col 17: 'GameLoopHtml.state=' ('(GameLoopHtmlState) → void') isn't a valid override of 'GameLoop.state=' ('(GameLoopState) → void').

Fix lib/src/game_loop_isolate/game_loop_isolate.dart. (-1.49 points)

Analysis of lib/src/game_loop_isolate/game_loop_isolate.dart reported 3 hints:

line 25 col 8: The value of the field '_initialized' isn't used.

line 31 col 10: The value of the field '_nextResize' isn't used.

line 57 col 10: The value of the field '_timeLost' isn't used.

Format lib/game_loop_common.dart.

Run dartfmt to format lib/game_loop_common.dart.

Fix additional 15 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/game_loop_html.dart (Run dartfmt to format lib/game_loop_html.dart.)
  • lib/src/game_loop_common/game_loop.dart (Run dartfmt to format lib/src/game_loop_common/game_loop.dart.)
  • lib/src/game_loop_common/game_loop_analog_input.dart (Run dartfmt to format lib/src/game_loop_common/game_loop_analog_input.dart.)
  • lib/src/game_loop_common/game_loop_digital_input.dart (Run dartfmt to format lib/src/game_loop_common/game_loop_digital_input.dart.)
  • lib/src/game_loop_common/game_loop_position_input.dart (Run dartfmt to format lib/src/game_loop_common/game_loop_position_input.dart.)
  • lib/src/game_loop_common/game_loop_state.dart (Run dartfmt to format lib/src/game_loop_common/game_loop_state.dart.)
  • lib/src/game_loop_common/game_loop_timer.dart (Run dartfmt to format lib/src/game_loop_common/game_loop_timer.dart.)
  • lib/src/game_loop_common/simple_state.dart (Run dartfmt to format lib/src/game_loop_common/simple_state.dart.)
  • lib/src/game_loop_html/game_loop_gamepad.dart (Run dartfmt to format lib/src/game_loop_html/game_loop_gamepad.dart.)
  • lib/src/game_loop_html/game_loop_html_state.dart (Run dartfmt to format lib/src/game_loop_html/game_loop_html_state.dart.)
  • lib/src/game_loop_html/game_loop_keyboard.dart (Run dartfmt to format lib/src/game_loop_html/game_loop_keyboard.dart.)
  • lib/src/game_loop_html/game_loop_mouse.dart (Run dartfmt to format lib/src/game_loop_html/game_loop_mouse.dart.)
  • lib/src/game_loop_html/game_loop_touch.dart (Run dartfmt to format lib/src/game_loop_html/game_loop_touch.dart.)
  • lib/src/game_loop_html/menu_state.dart (Run dartfmt to format lib/src/game_loop_html/menu_state.dart.)
  • lib/src/game_loop_html/simple_html_state.dart (Run dartfmt to format lib/src/game_loop_html/simple_html_state.dart.)

Maintenance issues and suggestions

Add SDK constraint in pubspec.yaml. (-50 points)

For information about setting SDK constraint, please see https://www.dartlang.org/tools/pub/pubspec#sdk-constraints.

Package is too old. (-100 points)

The package was released more than two years ago.

Homepage does not exists. (-20 points)

We were unable to access https://github.com/johnmccutchan/game_loop at the time of the analysis.

Documentation URL does not exists. (-10 points)

We were unable to access http://dartgamedevs.org/packages/game_loop/docs/game_loop.html at the time of the analysis.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use game_loop.dart.

Dependencies

Package Constraint Resolved Available
Dev dependencies
browser any
unittest any