Difference between revisions of "Controller"
m (Text replacement - "<source" to "<syntaxhighlight") |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
Line 55: | Line 55: | ||
print("Player: ", e.playerId, "disconnected") | print("Player: ", e.playerId, "disconnected") | ||
end) | end) | ||
− | </ | + | </syntaxhighlight> |
{|- | {|- |
Revision as of 14:27, 13 July 2023
Supported platforms:
Available since: Gideros 2014.01
Inherits from: EventDispatcher
Description
The 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)
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)
MethodsController:getControllerName gets the name of the controller |
EventsEvent.CONNECTED Constants |