I've recently been trying to do some android stuff and am now trying to read input from the accelerometer.
The changelog says that you can do the same way as a joystick. Can someone tell me what I'm doing wrong?
function love.load()
joystick = "Android Accelerometer"
end
function love.update()
axes = joystick:getAxisCount( )
end
function love.draw()
local joysticks = love.joystick.getJoysticks()
for i, joystick in ipairs(joysticks) do
love.graphics.print(joystick:getName(), 10, i * 20)
end
end
HugoBDesigner wrote:You have to do love.joystick.getJoysticks() to get the joysticks. Right now, you set the joystick as a string "Android Accelerometer".
I made a small love program to output all active joysticks here is a screenshot
Attachments
screenshot
Screenshot_2016-01-06-14-12-50.png (4.35 KiB) Viewed 3326 times
local joystick, position, speed
function love.load()
joystick = love.joystick.getJoysticks()[1]
position = {x = 0, y = 0}
speed = 10
end
function love.update(dt)
if joystick then
local axis1, axis2 = joystick:getAxes()
position.x, position.y = position.x + axis1 * speed * dt, position.y + axis2 * speed * dt
end
end
function love.draw()
love.graphics.circle("fill", position.x, position.y, 50)
end
Code is untested though, and uses plain Axes instead of the gamepad api, because i was uncertain whether the accelerometers would be detected by it or not.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
local joystick, position, speed
function love.load()
joysticks = love.joystick.getJoysticks()
looped = 0
for i in ipairs(joysticks) do
looped = looped + 1
end
joystick = joysticks[looped]
position = {x = 0, y = 0}
speed = 10
end
function love.update(dt)
if joystick then
axis1, axis2 = joystick:getAxes()
position.x, position.y = position.x + axis1 * speed * dt, position.y + axis2 * speed * dt
end
end
function love.draw()
love.graphics.circle("fill", position.x, position.y, 50)
end
-- in love.load:
-- ...
joysticks = love.joystick.getJoysticks()
joystick = joysticks[#joysticks] -- no need for the for loop
-- ...
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.