Difference between revisions of "Controller"

From GiderosMobile
Line 54: Line 54:
 
| style="width: 50%;"|
 
| style="width: 50%;"|
 
=== Methods ===
 
=== Methods ===
[[Controller:getControllerName]] - gets the name of controller<br/>
+
[[Controller:getControllerName]] {{<translate>gets the name of controller</translate>}}<br/>
[[Controller:getPlayerCount]] - returns amount of connected controllers<br/>
+
[[Controller:getPlayerCount]] {{<translate>returns amount of connected controllers</translate>}}<br/>
[[Controller:getPlayers]] - returns table with controller IDs<br/>
+
[[Controller:getPlayers]] {{<translate>returns table with controller IDs</translate>}}<br/>
[[Controller:isAnyAvailable]] - return true if any controller is connected<br/>
+
[[Controller:isAnyAvailable]] {{<translate>return true if any controller is connected</translate>}}<br/>
[[Controller:vibrate]] - vibrate the controller for provided amount of miliseconds<br/>
+
[[Controller:vibrate]] {{<translate>vibrate the controller for provided amount of miliseconds</translate>}}<br/>
 
| style="width: 50%;"|
 
| style="width: 50%;"|
 
=== Events ===
 
=== Events ===

Revision as of 14:19, 23 August 2018

Supported platforms:
Available since: 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 [1](Controller Interface Guide)

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

Controller:getControllerName Template:Gets the name of controller
Controller:getPlayerCount Template:Returns amount of connected controllers
Controller:getPlayers Template:Returns table with controller IDs
Controller:isAnyAvailable Template:Return true if any controller is connected
Controller:vibrate Template:Vibrate the controller for provided amount of miliseconds

Events

Event.CONNECTED
Event.DISCONNECTED
Event.KEY_DOWN
Event.KEY_UP
Event.LEFT_JOYSTICK
Event.LEFT_TRIGGER
Event.RIGHT_JOYSTICK
Event.RIGHT_TRIGGER

Constants