Controller

Inherits: EventDispatcher

Supported platforms:

Available since version: Gideros 2014.01

Description:

Controller interface allows you to use most popular controllers on all supported operating systems under the same interface.
Internally Controller Interface also matches all buttons and controller behavior under the same scheme so you won't have to worry about that anymore.
For more information check out Controller Interface Guide

Installation guide:

Android

Copy libs folder into your exported project

Copy src folder into your exported project

Add System.loadLibrary("controller"); to your main activity

Add "com.giderosmobile.android.plugins.controller.GControllerManager" as external class in your main activity

Add import com.giderosmobile.android.plugins.controller.GControllerDefault; to the import section of your main activity

Modify onKeyDown event in your main activity like this:


@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
	if(GControllerDefault.onKeyDown(keyCode, event))
		return true;
	GiderosApplication app = GiderosApplication.getInstance();
	if (app != null && app.onKeyDown(keyCode, event) == true)
		return true;
		
	return super.onKeyDown(keyCode, event);
}

Modify onKeyUp event in your main activity like this:


@Override
public boolean onKeyUp(int keyCode, KeyEvent event)
{
	if(GControllerDefault.onKeyUp(keyCode, event))
		return true;
	GiderosApplication app = GiderosApplication.getInstance();
	if (app != null && app.onKeyUp(keyCode, event) == true)
		return true;
		
	return super.onKeyUp(keyCode, event);
}

Add onGenericMotionEvent event in your main activity like this:


public boolean onGenericMotionEvent(MotionEvent event) {
	if(GControllerDefault.onGenericMotionEvent(event))
		return true;
	return super.onGenericMotionEvent(event);
}

Windows

Copy controller.dll into Plugins folder inside your Gideros installation directory

Mac

Copy libcontroller.dylib into Plugins folder inside your Gideros installation directory

IOS

Copy files you will use into your project

Add the files to xCode

Add IOS7 Game Controller framework as optional

Common uses and examples:

Using Controller example

require "controller"

controller:addEventListener(Event.KEY_DOWN, function(e)
	print("Button Down ", e.playerId, e.keyCode, findKeyCode(e.keyCode))
end)

controller:addEventListener(Event.KEY_UP, function(e)
	print("Button Up ", e.playerId, e.keyCode, findKeyCode(e.keyCode))
end)

controller:addEventListener(Event.RIGHT_JOYSTICK, function(e)
	print("Player: ", e.playerId)
	print("RIGHT_JOYSTICK:", "x:"..e.x, "y:"..e.y, "angle:"..e.angle, "strength:"..e.strength)
end)

controller:addEventListener(Event.LEFT_JOYSTICK, function(e)
	print("Player: ", e.playerId)
	print("LEFT_JOYSTICK:", "x:"..e.x, "y:"..e.y, "angle:"..e.angle, "strength:"..e.strength)
end)

controller:addEventListener(Event.RIGHT_TRIGGER, function(e)
	print("Player: ", e.playerId)
	print("RIGHT_TRIGGER:", "strength:"..e.strength)
end)

controller:addEventListener(Event.LEFT_TRIGGER, function(e)
	print("Player: ", e.playerId)
	print("LEFT_TRIGGER:", "strength:"..e.strength)
end)

controller:addEventListener(Event.CONNECTED, function(e)
	print("Player: ", e.playerId, "connected")
	print("Are there any controllers?", controller:isAnyAvailable())
	print("Controller count", controller:getPlayerCount())
	print("Name of controller "..e.playerId, controller:getControllerName(e.playerId))
	print("players", #controller:getPlayers())
end)

controller:addEventListener(Event.DISCONNECTED, function(e)
	print("Player: ", e.playerId, "disconnected")
end)

Methods, events and properties: