Difference between revisions of "love.joystickaxis"

(Returns)
(Example: Replaced nonsensical example. Fixed heading level.)
 
Line 13: Line 13:
 
Nothing.
 
Nothing.
  
=== Example ===
+
== Examples ==
 +
=== Show the value of the first two joystick axes ===
 
<source lang="Lua">
 
<source lang="Lua">
function love.joystickaxis( joystick, axis, value )
+
local lastAxis1Value = 0
 +
local lastAxis2Value = 0
 +
 
 +
function love.joystickaxis(joystick, axis, value)
 
if axis == 1 then
 
if axis == 1 then
position.x = position.x + 1/60*speed * value
+
lastAxis1Value = value
 
elseif axis == 2 then
 
elseif axis == 2 then
position.y = position.y + 1/60*speed * value
+
lastAxis2Value = value
 
end
 
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
 
end
 
</source>
 
</source>

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.

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