thrungames

Events

Events is very import for a game. Its the way you get input from the user like key inputs and mouse clicks. Thrunium improves some of these events and makes them easier to use. Here are the complete list of the events that Thrunium comes with. See all js events

Mouse

click

Click is triggered when the user clicks on your game. It updates your mouse position and you can add a callback to this event by setting this value to a function.

var game = new THRUNIUM.Game(400, 400);
game.click = function(e) {
	// your code here
};

mousedown

Mousedown is triggered when the user presses the mouse button in your game. It updates your mouse position and you can add a callback to this event by setting this value to a function.

var game = new THRUNIUM.Game(400, 400);
game.mousedown = function(e) {
	// your code here
};

mouseup

Mouseup is triggered when the user releases the mouse button in your game. It updates your mouse position and you can add a callback to this event by setting this value to a function.

var game = new THRUNIUM.Game(400, 400);
game.mouseup = function(e) {
	// your code here
};

mousemove

Mousemove is triggered when the user moves the mouse around. It updates your mouse position and you can add a callback to this event by setting this value to a function.

var game = new THRUNIUM.Game(400, 400);
game.mousemove = function(e) {
	// your code here
};

Touch

touch

Touch is triggered when the user touches your game with a touchscreen. It updates your mouse position and you can add a callback to this event by setting this value to a function.

var game = new THRUNIUM.Game(400, 400);
game.touch = function(e) {
	// your code here
};

touchstart

Touchstart is triggered when the user touches your game with a touchscreen the first time. It updates your mouse position and you can add a callback to this event by setting this value to a function.

var game = new THRUNIUM.Game(400, 400);
game.touchstart = function(e) {
	// your code here
};

touchend

Touchend is triggered when the user releases the touch with a touchscreen. It updates your mouse position and you can add a callback to this event by setting this value to a function.

var game = new THRUNIUM.Game(400, 400);
game.touchend = function(e) {
	// your code here
};

Keys

keydown

Keydown is triggered when the user presses a key down. You can add a callback to this event by setting this value to a function. Find key codes at keycode.info

var game = new THRUNIUM.Game(400, 400);
game.keydown = function(e) {
	// your code here
	console.log(e.keyCode, e.key);
};

keyup

Keyup is triggered when the user releases a key. You can add a callback to this event by setting this value to a function.

var game = new THRUNIUM.Game(400, 400);
game.keyup = function(e) {
	// your code here
	console.log(e.keyCode. e.key);
};

Device

deviceorientation

Deviceorientation is triggered when the orientation of the device changes. You can add a callback to this event by setting this value to a function. This usually only works on phones.

var game = new THRUNIUM.Game(400, 400);
game.deviceorientation = function(e) {
	// your code here
};