having issues reading gamepad - hat and buttons
Posted: Tue Aug 24, 2021 12:38 am
I am trying to use the hat to move a sprite left and right and the A button to fire, I've spent all day trying to figure this out.
Here's my code, any help would be appreciated:
--move turret
function move_turret()
--don't move it if turret is exploding
if not turret_hit then
--if love.keyboard.isDown("left") then
if Joystick:getHat( "l" ) then
if tx >= lb + 2 then
tx = tx - 4
end
--elseif love.keyboard.isDown("right") then
elseif Joystick:getHat( "r" ) then
if tx <= rb - 8 then
tx = tx + 4
end
end
end
end
--fire turret
function fire_turret()
--if love.keyboard.isDown("space") then
if love.joystick.isDown( 0, "x" ) then
love.audio.play( pew_sound )
--pressed = true
t_fired = true
t_shot_x = tx
t_shot_y = ty
end
end
Here's my code, any help would be appreciated:
--move turret
function move_turret()
--don't move it if turret is exploding
if not turret_hit then
--if love.keyboard.isDown("left") then
if Joystick:getHat( "l" ) then
if tx >= lb + 2 then
tx = tx - 4
end
--elseif love.keyboard.isDown("right") then
elseif Joystick:getHat( "r" ) then
if tx <= rb - 8 then
tx = tx + 4
end
end
end
end
--fire turret
function fire_turret()
--if love.keyboard.isDown("space") then
if love.joystick.isDown( 0, "x" ) then
love.audio.play( pew_sound )
--pressed = true
t_fired = true
t_shot_x = tx
t_shot_y = ty
end
end