Difference between revisions of "love.gamepadaxis"

m
(Example: Cleaned up example.)
 
(3 intermediate revisions by 2 users not shown)
Line 4: Line 4:
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
love.gamepadaxis( joystick, axis )
+
love.gamepadaxis( joystick, axis, value )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
 
{{param|Joystick|joystick|The joystick object.}}
 
{{param|Joystick|joystick|The joystick object.}}
 
{{param|GamepadAxis|axis|The virtual gamepad axis.}}
 
{{param|GamepadAxis|axis|The virtual gamepad axis.}}
 +
{{param|number|value|The new axis value.}}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
 +
 +
== Example ==
 +
Update the position of an object when an axis moves.
 +
 +
<source lang="lua">
 +
function love.load()
 +
width, height = love.graphics.getDimensions()
 +
position      = {x = width/2, y = height/2}
 +
end
 +
 +
function love.gamepadaxis(joystick, axis, value)
 +
if axis == "leftx" then
 +
position.x = width/2 + value*width/2
 +
elseif axis == "lefty" then
 +
position.y = height/2 + value*height/2
 +
end
 +
end
 +
 +
function love.draw()
 +
love.graphics.circle("fill", position.x, position.y, 50)
 +
end
 +
</source>
  
 
== See Also ==
 
== See Also ==
Line 19: Line 42:
 
{{#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}}

Latest revision as of 18:57, 11 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

Update the position of an object when an axis moves.

function love.load()
	width, height = love.graphics.getDimensions()
	position      = {x = width/2, y = height/2}
end

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

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

See Also


Other Languages