Difference between revisions of "Controller"

From GiderosMobile
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
<!-- GIDEROSOBJ:Controller -->
 
<!-- GIDEROSOBJ:Controller -->
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/>
+
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/>
'''<translate>Available since</translate>:''' Gideros 2014.01<br/>
+
'''Available since:''' Gideros 2014.01<br/>
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/EventDispatcher|EventDispatcher]]<br/>
+
'''Inherits from:''' [[EventDispatcher]]<br/>
=== <translate>Description</translate> ===
+
 
<translate>Controller interface allows you to use most popular controllers on all supported operating systems under the same interface.
+
=== 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 more information check out [http://docs.giderosmobile.com/interface/controller](Controller Interface Guide)</translate>
+
For more information check out [http://docs.giderosmobile.com/interface/controller]('''Controller Interface Guide''')
=== <translate>Examples</translate> ===
+
 
'''Using Controller example'''<br/>
+
=== Example ===
<source lang="lua">require "controller"
+
<source lang="lua">
 +
require "controller"
  
 
controller:addEventListener(Event.KEY_DOWN, function(e)
 
controller:addEventListener(Event.KEY_DOWN, function(e)
Line 53: Line 54:
 
controller:addEventListener(Event.DISCONNECTED, function(e)
 
controller:addEventListener(Event.DISCONNECTED, function(e)
 
print("Player: ", e.playerId, "disconnected")
 
print("Player: ", e.playerId, "disconnected")
end)</source>
+
end)
 +
</source>
 +
 
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Methods</translate> ===
+
=== Methods ===
[[Special:MyLanguage/Controller:getControllerName|Controller:getControllerName]] ''<translate>gets the name of controller</translate>''<br/><!-- GIDEROSMTD:Controller:getControllerName(id) gets the name of controller -->
+
[[Controller:getControllerName]] ''gets the name of the controller''<br/><!--GIDEROSMTD:Controller:getControllerName(id) gets the name of the controller-->
[[Special:MyLanguage/Controller:getPlayerCount|Controller:getPlayerCount]] ''<translate>returns amount of connected controllers</translate>''<br/><!-- GIDEROSMTD:Controller:getPlayerCount() returns amount of connected controllers -->
+
[[Controller:getPlayerCount]] ''returns the amount of connected controllers''<br/><!--GIDEROSMTD:Controller:getPlayerCount() returns the amount of connected controllers-->
[[Special:MyLanguage/Controller:getPlayers|Controller:getPlayers]] ''<translate>returns table with controller IDs</translate>''<br/><!-- GIDEROSMTD:Controller:getPlayers() returns table with controller IDs -->
+
[[Controller:getPlayers]] ''returns a table with controller IDs''<br/><!--GIDEROSMTD:Controller:getPlayers() returns a table with controller IDs-->
[[Special:MyLanguage/Controller:isAnyAvailable|Controller:isAnyAvailable]] ''<translate>return true if any controller is connected</translate>''<br/><!-- GIDEROSMTD:Controller:isAnyAvailable() return true if any controller is connected -->
+
[[Controller:isAnyAvailable]] ''returns true if any controller is connected''<br/><!--GIDEROSMTD:Controller:isAnyAvailable() returns true if any controller is connected-->
[[Special:MyLanguage/Controller:vibrate|Controller:vibrate]] ''<translate>vibrate the controller for provided amount of miliseconds</translate>''<br/><!-- GIDEROSMTD:Controller:vibrate(ms) vibrate the controller for provided amount of miliseconds -->
+
[[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;"|
=== <translate>Events</translate> ===
+
=== Events ===
[[Special:MyLanguage/Event.CONNECTED|Event.CONNECTED]]<br/><!-- GIDEROSEVT:Event.CONNECTED connected-->
+
[[Event.CONNECTED]]<br/><!--GIDEROSEVT:Event.CONNECTED connected-->
[[Special:MyLanguage/Event.DISCONNECTED|Event.DISCONNECTED]]<br/><!-- GIDEROSEVT:Event.DISCONNECTED disconnected-->
+
[[Event.DISCONNECTED]]<br/><!--GIDEROSEVT:Event.DISCONNECTED disconnected-->
[[Special:MyLanguage/Event.KEY_DOWN|Event.KEY_DOWN]]<br/><!-- GIDEROSEVT:Event.KEY_DOWN keyDown-->
+
[[Event.KEY_DOWN]]<br/><!--GIDEROSEVT:Event.KEY_DOWN keyDown-->
[[Special:MyLanguage/Event.KEY_UP|Event.KEY_UP]]<br/><!-- GIDEROSEVT:Event.KEY_UP keyUp-->
+
[[Event.KEY_UP]]<br/><!--GIDEROSEVT:Event.KEY_UP keyUp-->
[[Special:MyLanguage/Event.LEFT_JOYSTICK|Event.LEFT_JOYSTICK]]<br/><!-- GIDEROSEVT:Event.LEFT_JOYSTICK leftJoystick-->
+
[[Event.LEFT_JOYSTICK]]<br/><!--GIDEROSEVT:Event.LEFT_JOYSTICK leftJoystick-->
[[Special:MyLanguage/Event.LEFT_TRIGGER|Event.LEFT_TRIGGER]]<br/><!-- GIDEROSEVT:Event.LEFT_TRIGGER leftTrigger-->
+
[[Event.LEFT_TRIGGER]]<br/><!--GIDEROSEVT:Event.LEFT_TRIGGER leftTrigger-->
[[Special:MyLanguage/Event.RIGHT_JOYSTICK|Event.RIGHT_JOYSTICK]]<br/><!-- GIDEROSEVT:Event.RIGHT_JOYSTICK rightJoystick-->
+
[[Event.RIGHT_JOYSTICK]]<br/><!--GIDEROSEVT:Event.RIGHT_JOYSTICK rightJoystick-->
[[Special:MyLanguage/Event.RIGHT_TRIGGER|Event.RIGHT_TRIGGER]]<br/><!-- GIDEROSEVT:Event.RIGHT_TRIGGER rightTrigger-->
+
[[Event.RIGHT_TRIGGER]]<br/><!--GIDEROSEVT:Event.RIGHT_TRIGGER rightTrigger-->
=== <translate>Constants</translate> ===
+
=== Constants ===
 
|}
 
|}
  
 
{{GIDEROS IMPORTANT LINKS}}
 
{{GIDEROS IMPORTANT LINKS}}

Revision as of 23:26, 1 March 2023

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.png
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)

Methods

Controller:getControllerName gets the name of the controller
Controller:getPlayerCount returns the amount of connected controllers
Controller:getPlayers returns a table with controller IDs
Controller:isAnyAvailable returns true if any controller is connected
Controller:vibrate vibrates 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