Difference between revisions of "Controller"
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | |||
<!-- GIDEROSOBJ:Controller --> | <!-- GIDEROSOBJ:Controller --> | ||
− | ''' | + | '''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/> |
− | ''' | + | '''Available since:''' Gideros 2014.01<br/> |
− | ''' | + | '''Inherits from:''' [[EventDispatcher]]<br/> |
− | === | + | |
− | + | === 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. | 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 | + | '''For a FULL DEMO please see Gideros Studio, Example Projects, Hardware, Controller Plugin Demo''' |
− | === | + | |
− | + | === Example === | |
− | < | + | <syntaxhighlight lang="lua"> |
+ | require "controller" | ||
+ | |||
+ | function findKeyCode(code) | ||
+ | for i, val in pairs(KeyCode) do | ||
+ | if val == code then return i end | ||
+ | end | ||
+ | return "unknown" | ||
+ | end | ||
controller:addEventListener(Event.KEY_DOWN, function(e) | controller:addEventListener(Event.KEY_DOWN, function(e) | ||
Line 53: | Line 61: | ||
controller:addEventListener(Event.DISCONNECTED, function(e) | controller:addEventListener(Event.DISCONNECTED, function(e) | ||
print("Player: ", e.playerId, "disconnected") | print("Player: ", e.playerId, "disconnected") | ||
− | end)</ | + | end) |
+ | </syntaxhighlight> | ||
+ | |||
{|- | {|- | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | === | + | === Methods === |
− | [[ | + | [[Controller:getControllerName]] ''gets the name of the controller''<br/><!--GIDEROSMTD:Controller:getControllerName(id) gets the name of the controller--> |
− | [[ | + | [[Controller:getPlayerCount]] ''returns the amount of connected controllers''<br/><!--GIDEROSMTD:Controller:getPlayerCount() returns the amount of connected controllers--> |
− | [[ | + | [[Controller:getPlayers]] ''returns a table with controller IDs''<br/><!--GIDEROSMTD:Controller:getPlayers() returns a table with controller IDs--> |
− | [[ | + | [[Controller:isAnyAvailable]] ''returns true if any controller is connected''<br/><!--GIDEROSMTD:Controller:isAnyAvailable() returns true if any controller is connected--> |
− | [[ | + | [[Controller:vibrate]] ''vibrates the controller for provided amount of miliseconds''<br/><!--GIDEROSMTD:Controller:vibrate(ms) vibrates the controller for provided amount of miliseconds--> |
+ | |||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
− | === | + | === Events === |
− | [[ | + | [[Event.CONNECTED]]<br/><!--GIDEROSEVT:Event.CONNECTED connected--> |
− | [[ | + | [[Event.DISCONNECTED]]<br/><!--GIDEROSEVT:Event.DISCONNECTED disconnected--> |
− | [[ | + | [[Event.KEY_DOWN]]<br/><!--GIDEROSEVT:Event.KEY_DOWN keyDown--> |
− | [[ | + | [[Event.KEY_UP]]<br/><!--GIDEROSEVT:Event.KEY_UP keyUp--> |
− | [[ | + | [[Event.LEFT_JOYSTICK]]<br/><!--GIDEROSEVT:Event.LEFT_JOYSTICK leftJoystick--> |
− | [[ | + | [[Event.LEFT_TRIGGER]]<br/><!--GIDEROSEVT:Event.LEFT_TRIGGER leftTrigger--> |
− | [[ | + | [[Event.RIGHT_JOYSTICK]]<br/><!--GIDEROSEVT:Event.RIGHT_JOYSTICK rightJoystick--> |
− | [[ | + | [[Event.RIGHT_TRIGGER]]<br/><!--GIDEROSEVT:Event.RIGHT_TRIGGER rightTrigger--> |
− | === | + | === Constants === |
|} | |} | ||
+ | |||
+ | {{GIDEROS IMPORTANT LINKS}} |
Latest revision as of 00:18, 12 October 2024
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 a FULL DEMO please see Gideros Studio, Example Projects, Hardware, Controller Plugin Demo
Example
require "controller"
function findKeyCode(code)
for i, val in pairs(KeyCode) do
if val == code then return i end
end
return "unknown"
end
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 |