What's up with gamepad axes?
Posted: Fri Apr 28, 2023 1:46 pm
Hi there, I am once again meandering into the love forums with a question.
So I decided it would be neat to look into controller support for my game, so I made a quick test project to try out joysticks, however I got some weird results.
The project is pretty simple - draw a circle based on the axis values, and also draw a point on a canvas behind you, which has resulted in this image when just moving the stick in a circle: What's the deal with this? I would have expected either a perfect circle or a square, but not this? It's not even consistent with where it draws the line. My code is as follows:
So I decided it would be neat to look into controller support for my game, so I made a quick test project to try out joysticks, however I got some weird results.
The project is pretty simple - draw a circle based on the axis values, and also draw a point on a canvas behind you, which has resulted in this image when just moving the stick in a circle: What's the deal with this? I would have expected either a perfect circle or a square, but not this? It's not even consistent with where it draws the line. My code is as follows:
Code: Select all
function love.load()
circle = {}
circle.x = 0
circle.y = 0
love.window.setMode(0,0)
joysticks = love.joystick.getJoysticks()
joystick = joysticks[1]
drawCanvas = love.graphics.newCanvas()
end
function love.update(dt)
joysticks = love.joystick.getJoysticks()
joystick = joysticks[1]
local distance = 500
if joystick and joystick:isGamepad() then
circle.x = joystick:getGamepadAxis("leftx")*distance
circle.y = joystick:getGamepadAxis("lefty")*distance
end
end
function love.draw()
if joystick and joystick:isGamepad() then
love.graphics.setBackgroundColor(0,0,0)
else
love.graphics.setBackgroundColor(1,0,0)
end
drawCanvas:renderTo(
function()
love.graphics.circle("fill", circle.x+love.graphics.getWidth()/2, circle.y+love.graphics.getHeight()/2, 1)
end
)
love.graphics.circle("line", circle.x+love.graphics.getWidth()/2, circle.y+love.graphics.getHeight()/2, 50)
love.graphics.draw(drawCanvas,0,0)
end
function love.keypressed(key)
if key == "escape" then
love.event.quit()
end
end