Skip to content
/ Joystix Public

Javascript module that proxies different controller types and provides a simple interface. Gamepad API / MultiTouch / Keyboard

Notifications You must be signed in to change notification settings

cham/Joystix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Joystix

Joystix is a javascript object that proxies several different input types to provide input for games

The following APIs and libraries are used, in this order of preference, depending on support:

  • GamepadAPI
  • Seb Lee-Delisle's MultiTouch joystick
  • Keyboard controls (arrows / WASD to move and space bar for fire)

GamepadAPI support from http://www.html5rocks.com/en/tutorials/doodles/gamepad/

MultiTouch joystick from http://seb.ly/2011/04/multi-touch-game-controller-in-javascripthtml5-for-ipad/

===========

Joystix requires (and is bundled with)

  • Require.js
  • Underscore.js
  • jQuery

===========

See js/main.js for example usage but here's the tl;dr

var controller = new Joystix({
	$window: $(window)
});

controller.onMove(function(movement){
	if(movement.x1){
		if(movement.x1 > 0){
			console.log('Right!');
		}else if(movement.x1 < 0){
			console.log('Left!');
		}
	}
	if(movement.y1){
		if(movement.y1 > 0){
			console.log('Down!');
		}else if(movement.y1 < 0){
			console.log('Up!');
		}
	}
});

controller.onButtonPress(function(buttonPresses){
	if(buttonPresses[0]){
		console.log('Fire!');
	}
});

About

Javascript module that proxies different controller types and provides a simple interface. Gamepad API / MultiTouch / Keyboard

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published