science-halt

0.2.0 • Public • Published

science-halt

usage

var scihalt = require('science-halt');
 
scihalt(function(){
  // do something when ESC is pressed
})

rationale

This is a stupid module. Everytime I make a game loop, I do something like this:

var last = Date.now()
  , running = true;
 
(function anim() {
  if (running) requestAnimationFrame(anim);
  var now = Date.now();
  doUpdate(now - last);
  last = now;
}());
 
document.addEventListener('keydown', function(e) {
  if (e.which == 27) {
    running = false;
    console.log('HALT IN THE NAME OF SCIENCE!');
  }
})

This module takes care of the keybinding for halting... because apparently I find 27 a really hard number to remember. The above example becomes:

var scihalt = require('science-halt');
 
var last = Date.now()
  , running = true;
 
(function anim() {
  if (running) requestAnimationFrame(anim);
  var now = Date.now();
  doUpdate(now - last);
  last = now;
}());
 
scihalt(function() { running = false; })

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.2.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.2.0
    0
  • 0.1.0
    1

Package Sidebar

Install

npm i science-halt

Weekly Downloads

1

Version

0.2.0

License

MIT

Last publish

Collaborators

  • kirbysayshi