Difference between revisions of "love.joystickaxis"
(Created page) |
(→Example: Replaced nonsensical example. Fixed heading level.) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 7: | Line 7: | ||
</source> | </source> | ||
=== Arguments === | === Arguments === | ||
− | {{param| | + | {{param|Joystick|joystick|The joystick object.}} |
{{param|number|axis|The axis number.}} | {{param|number|axis|The axis number.}} | ||
{{param|number|value|The new axis value.}} | {{param|number|value|The new axis value.}} | ||
=== Returns === | === Returns === | ||
Nothing. | Nothing. | ||
+ | |||
+ | == Examples == | ||
+ | === Show the value of the first two joystick axes === | ||
+ | <source lang="Lua"> | ||
+ | local lastAxis1Value = 0 | ||
+ | local lastAxis2Value = 0 | ||
+ | |||
+ | function love.joystickaxis(joystick, axis, value) | ||
+ | if axis == 1 then | ||
+ | lastAxis1Value = value | ||
+ | elseif axis == 2 then | ||
+ | lastAxis2Value = value | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function love.draw() | ||
+ | love.graphics.print(string.format("Axis 1: %.2f", lastAxis1Value), 100, 100) | ||
+ | love.graphics.print(string.format("Axis 2: %.2f", lastAxis2Value), 100, 120) | ||
+ | end | ||
+ | </source> | ||
+ | |||
== See Also == | == See Also == | ||
* [[parent::love]] | * [[parent::love]] | ||
[[Category:Callbacks]] | [[Category:Callbacks]] | ||
{{#set:Description=Called when a joystick axis moves.}} | {{#set:Description=Called when a joystick axis moves.}} | ||
+ | {{#set:Subcategory=Joystick}} | ||
== Other Languages == | == Other Languages == | ||
{{i18n|love.joystickaxis}} | {{i18n|love.joystickaxis}} |
Latest revision as of 09:11, 23 November 2021
Available since LÖVE 0.9.0 |
This callback is not supported in earlier versions. |
Called when a joystick axis moves.
Contents
Function
Synopsis
love.joystickaxis( joystick, axis, value )
Arguments
Joystick joystick
- The joystick object.
number axis
- The axis number.
number value
- The new axis value.
Returns
Nothing.
Examples
Show the value of the first two joystick axes
local lastAxis1Value = 0
local lastAxis2Value = 0
function love.joystickaxis(joystick, axis, value)
if axis == 1 then
lastAxis1Value = value
elseif axis == 2 then
lastAxis2Value = value
end
end
function love.draw()
love.graphics.print(string.format("Axis 1: %.2f", lastAxis1Value), 100, 100)
love.graphics.print(string.format("Axis 2: %.2f", lastAxis2Value), 100, 120)
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info