Controller Inputs

Inputs

name touch count description
draw 1 free drawing of shapes such as Circle, Triangle and Rectangle.
edge 2 moves an edge with two circles for each finger.
touch 1 send touch events for one finger only. No draw feedback.
disc 1 moves a disc when touching using one finger.
drag 1 lets you drag and drop shapes (one at a time).

A script can enable an input event generation:

UB.controller(playerID).enableInput("draw");

touch

Event names

A script can enable, listen to and handle the touchEnd the event:

UB.controller(playerID).enableInput("touch");

function handleTouchEnd(event) {
	console.log(event.data.playerID);
}

UB.game.on("touchEnd", handleTouchEnd);

Example event:

{
	"name": "touchEnd",
	"data":{
		"playerID": 0,
		"x" : 20,
		"y" : 24
	}
}

drag

Event names

In your script enable, listen to and handle the dragStart event:

UB.controller(playerID).enableInput("drag");

function handleDragStart(event) {
	console.log(event.data.spriteID);
}	
UB.game.on("dragStart", handleDragStart);	

Example event:

{
	"name": "dragStart",
	"data":{
		"playerID": 0,
		"type": "Circle",
		"layer": 0,
		"spriteID": 42,
		"x" : 80,
		"y" : 33
	}
}

draw

A gesture event is generated when the player draws any of the supported types.

Event names
Gesture type

touch strokes

Data types

Example script:

UB.controller(playerID).enableInput("draw");		
UB.game.on("gesture", function(event) {
	console.log(event.data.type);
	var x = (event.data.left + event.data.right) / 2;
	var y = (event.data.top + event.data.bottom) / 2;
	var w = (event.data.right - event.data.left);
	var h = (event.data.bottom - event.data.top);	
});

Example event:

{
	"name": "gesture",
	"data":{
		"playerID": 1,
		"type": "rectangle",
		"left" : 228,
		"right" : 374,
		"top" : 455,
		"bottom" : 599
	}
}

sprite

The sprite event is generated when the player touches and releases a Sprite. It can be used for GUI elements on the controller, e.g. for menus or other actions.

Event names

Example script:

UB.controller(playerID).enableInput("sprite");		
UB.game.on("spriteReleased", function(event) {
	console.log(event.data.spriteID);	
});

Example event:

{
	"name": "spriteReleased",
	"data":{
		"playerID": 1,
		"type": "Circle",
		"layer": 0,
		"spriteID": 42,
		"x" : 80,
		"y" : 33
	}
}