Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

crtrdg-arrows

0.0.2 • Public • Published

crtrdg-arrow

browser support

This module is designed for easy arrow control together with crtrdg. It is kind of like a more specific crtrdg-keyboard only for the use with self defined Arrow keys.

However it is designed to be independant so it can be used with browserify without using something else from the crtrdg ecosystem.

It supports events for the four directions as well as functions for directly asking the states of the arrows.

You can simply install is with npm install crtrdg-arrows and then use browserifyto transform it for the browser.

Simple Example with crtrdg-gameloop

var Game = require('crtrdg-gameloop');
var Arrows = require('crtrdg-arrows');
 
var game = new Game({
  canvasId: 'game',
  width: 800,
  height: 400,
  backgroundColor: '#ff1f1f'
});
 
var arrows = new Arrows();
 
var x = 10;
 
arrows.on('down', function () {
  // Will be called once on keydown
  console.log('This key is not allowed');
})
 
game.on('update', function(interval){
  if (arrows.isDown('left')) {
    x -= 5;
  }
  if (arrows.isDown('right')) {
    x += 5;
  }
});
 
game.on('draw', function (context) {
  context.fillStyle = '#fff';
  context.fillRect(x, 390, 60, 10);
});

Install

npm i crtrdg-arrows

DownloadsWeekly Downloads

0

Version

0.0.2

License

MIT

Last publish

Collaborators

  • avatar