Controller


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.

What Controller Interface provides:

  • Using same interface across all supported Operating systems
  • Using same interface across all supported controllers
  • Support for multiple controller types on same market/device (As playing with Xbox or Moga controller on OUYA)
  • Easier additions of support for future controllers
  • Providing controller layer, which would easily allow you to combine gameplay with or without controllers in the same app
  • Controller layer would easily allow you to port your touch based interface (as menu buttons) to controller selectable buttons

Gameplay guidelines/suggestions

Buttton A is always Yes/Accept, button B is always no/cancel/back

Don't use both Left joystick and dpad for different functionalities in your game, because for some controllers without joysticks, dpad matches both dpads digital button events and analog joystick events

Use BUTTON_MENU to pause your game and present menu in pause screen

Methods

  • controller:isAnyAvailable() - return bool, true if any controller is connected
  • controller:getPlayerCount() - get amount of connected players/controllers
  • controller:getControllerName(playerId) - get type of controller
  • controller:getPlayers() - return table with player Ids
  • controller:virbate(ms) - vibrate controller (if supported) for ms milliseconds

Events

  • Event.RIGHT_JOYSTICK
    • e.x - x vector
    • e.y - y vector
    • e.angle - angle of joystick
    • e.strength - distance vector from center
    • e.x - x vector
    • e.playerId - id of player/controller
  • Event.LEFT_JOYSTICK
    • e.x - x vector
    • e.y - y vector
    • e.angle - angle of joystick
    • e.strength - distance vector from center
    • e.x - x vector
    • e.playerId - id of player/controller
  • Event.KEY_DOWN
    • e.keyCode - which button was pressed
    • e.playerId - id of player/controller
  • Event.KEY_UP
    • e.keyCode - which button was released
    • e.playerId - id of player/controller
  • Event.RIGHT_TRIGGER
    • e.strength - strength of press (from 0 to 1)
    • e.playerId - id of player/controller
  • Event.LEFT_TRIGGER
    • e.strength - strength of press (from 0 to 1)
    • e.playerId - id of player/controller
  • Event.CONNECTED
    • e.playerId - id of player/controller
  • Event.DISCONNECTED
    • e.playerId - id of player/controller

Constants

  • KeyCode.BUTTON_A
  • KeyCode.BUTTON_B
  • KeyCode.BUTTON_X
  • KeyCode.BUTTON_Y
  • KeyCode.DPAD_DOWN
  • KeyCode.DPAD_UP
  • KeyCode.DPAD_LEFT
  • KeyCode.DPAD_RIGHT
  • KeyCode.BUTTON_MENU
  • KeyCode.BUTTON_BACK
  • KeyCode.BUTTON_L1
  • KeyCode.BUTTON_R1
  • KeyCode.BUTTON_L2
  • KeyCode.BUTTON_R2
  • KeyCode.BUTTON_L3
  • KeyCode.BUTTON_R3
  BUTTON_A BUTTON_B BUTTON_X BUTTON_Y BUTTON_MENU BUTTON_BACK BUTTON_L1 BUTTON_R1 BUTTON_L2 BUTTON_R2 BUTTON_L3 BUTTON_R3 DPAD_LEFT DPAD_RIGHT DPAD_UP DPAD_DOWN
Gametel
IOS: Button L1
Android: Button A
IOS: Button R1
Android: Button B
IOS: Select
Android: Button X
IOS: Start
Android: Button Y
IOS: Button B
Android: Start
IOS: Button A
Android: Select
IOS: Button Y
Android: Button L1
IOS: Button X
Android: Button R1
Does not exist
Does not exist
Does not exist
Does not exist
Direction Pad Left
Direction Pad Right
Direction Pad Up
Direction Pad Down
Green Throttle
Button A
Button B
Button X
Button Y
Start
System Button
Back button
Button L1
Button R1
Trigger L2
Trigger R2
Left Joystick
Right Joystick
Direction Pad Left
Direction Pad Right
Direction Pad Up
Direction Pad Down
ICade
Button A
Button B
Button X
Button Y
Right Trigger
Left Trigger
Button L1
Button R1
Does not exist
Does not exist
Does not exist
Does not exist
Direction Pad Left
Direction Pad Right
Direction Pad Up
Direction Pad Down
IOS7 MFI
Button A
Button B
Button X
Button Y
Pause
 
Button L1
Button R1
Button L2
Button R1
Does not exist
Does not exist
Direction Pad Left
Direction Pad Right
Direction Pad Up
Direction Pad Down
Moga
Button A
Button B
Button X
Button Y
Start
Select
Button L1
Button R1
Trigger L2
Trigger R2
Left Joystick
Right Joystick
Direction Pad Left
Direction Pad Right
Direction Pad Up
Direction Pad Down
OUYA
Button O
Button A
Button U
Button Y
System Button
no button
Button L1
Button R1
Trigger L2
Trigger R2
Left Joystick
Right Joystick
Direction Pad Left
Direction Pad Right
Direction Pad Up
Direction Pad Down
PS3 DS
Cross Button
Circle Button
Square Button
Triangle Button
System Button, Start Button
Select Button
Button L1
Button R1
Left Trigger
Right Trigger
Left Stick
Right Stick
Direction Pad Left
Direction Pad Right
Direction Pad Up
Direction Pad Down
Xbox
Button A
Button B
Button X
Button Y
Start
System Button 
Select
Button L1
Button R1
Trigger L2
Trigger R2
Left Joystick
Right Joystick
Direction Pad Left
Direction Pad Right
Direction Pad Up
Direction Pad Down
XPeria Play
Cross Button
Circle Button
Square Button
Triangle Button
Menu Button, Start Button
Select Button, Back Button
Button L
Button R
Does not exist
Does not exist
Does not exist
Does not exist
Direction Pad Left
Direction Pad Right
Direction Pad Up
Direction Pad Down

Legend:

Alpha
Beta
Stable
  windows MacOS Android IOS
Gametel
No support
No support
Android 3.1+
IOS 5+
Green Throttle
Only USB mode
Only USB mode
Android 4.0+
No support
ICade
No support
No support
No support
IOS 5+
IOS7 MFI
No support
No support
No support
IOS 7
Moga
No driver
No driver
Mode A Android 2.3 (with Moga SDK)
Mode B Android 3.1.x
No support
OUYA
Full support
Unusable (OUYA driver problems)
Android 3.1.x
No support
PS3 DS
As Xbox 360 Controller through MotionJoy DS3 tool
Full support
Full support
No support
Xbox
No event for System Button
Full support
Android 3.1.x
No support
XPeria Play
No support
No support
Android 3.1.x
No support

Legend:

Alpha
Beta
Stable

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);
}

  Files
Gametel
  • no specific files
Green Throttle
  • src\com\giderosmobile\android\plugins\controller\GControllerGreenThrottle.java
  • libs\JavaInputUnifierVersion.jar
Moga
  • (Files required only for Mode A support)
  • src\com\giderosmobile\android\plugins\controller\GControllerMoga.java
  • libs\com.bda.controller.jar
OUYA
  • no specific files
PS3 DS
  • no specific files
Xbox
  • no specific files
XPeria Play
  • no specific files

Legend:

Alpha
Beta
Stable

Copy files you will use into your project

Add the files to xCode

Add IOS7 Game Controller framework as optional

  Files
Gametel
  • Controller/GControllerIcade.h
  • Controller/GControllerIcade.m
  • Controller/iCadeReaderView.h
  • Controller/iCadeReaderView.m
  • Controller/iCadeState.h
ICade
  • Controller/GControllerIcade.h
  • Controller/GControllerIcade.m
  • Controller/iCadeReaderView.h
  • Controller/iCadeReaderView.m
  • Controller/iCadeState.h
IOS7 MFI
  • Controller/GControllerDefault.h
  • Controller/GControllerDefault.m

Legend:

Alpha
Beta
Stable

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

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

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)