Difference between revisions of "love.gamepadaxis"

m (Fixed arguments)
(See Also)
Line 12: Line 12:
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
 +
 +
== Example ==
 +
<source lang="lua">
 +
function love.load()
 +
width, height = love.graphics.getDimensions( )
 +
local joysticks = love.joystick.getJoysticks()
 +
joystick = joysticks[1]
 +
position = {x = width/2, y = height/2}
 +
end
 +
 +
function love.draw()
 +
function love.draw()
 +
love.graphics.circle("fill", position.x, position.y, 50)
 +
end
 +
end
 +
 +
function love.gamepadaxis( joystick, axis, value )
 +
if axis == "leftx" then
 +
position.x = width/2 + value*height/2
 +
elseif axis == "lefty" then
 +
position.y = height/2 + value*height/2
 +
end
 +
end
 +
</source>
  
 
== See Also ==
 
== See Also ==
Line 20: Line 44:
 
{{#set:Description=Called when a Joystick's virtual gamepad axis is moved.}}
 
{{#set:Description=Called when a Joystick's virtual gamepad axis is moved.}}
 
{{#set:Subcategory=Joystick}}
 
{{#set:Subcategory=Joystick}}
 +
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.gamepadaxis}}
 
{{i18n|love.gamepadaxis}}

Revision as of 21:44, 10 November 2021

Available since LÖVE 0.9.0
This function is not supported in earlier versions.

Called when a Joystick's virtual gamepad axis is moved.

Function

Synopsis

love.gamepadaxis( joystick, axis, value )

Arguments

Joystick joystick
The joystick object.
GamepadAxis axis
The virtual gamepad axis.
number value
The new axis value.

Returns

Nothing.

Example

function love.load()
	width, height = love.graphics.getDimensions( )
	local joysticks = love.joystick.getJoysticks()
	joystick = joysticks[1]
	position = {x = width/2, y = height/2}
end

function love.draw()
	function love.draw()
		love.graphics.circle("fill", position.x, position.y, 50)
	end
end

function love.gamepadaxis( joystick, axis, value )
	if axis == "leftx" then
		position.x = width/2 + value*height/2
	elseif axis == "lefty" then
		position.y = height/2 + value*height/2
	end
end

See Also


Other Languages