I am making a platformer that has mobile touch controls and the way that I made the jump button is in the touchpressed function I check if any button is pressed and then I check if a specific button is pressed like so
function love.touchpressed( id, x, y, dx, dy, pressure )
paddy.update() -- this checks if any button is pressed
if paddy.isDown('a') then -- this checks if the "a" button is pressed
player.collider:applyLinearImpulse(0,-50000)
end
end
now the jump button works correctly until I maintain the jump button and press anywhere else on the screen wich updates the touchpressed function, and I got genuinely stuck with this because I have no idea how to fix it so please help.
snibo wrote: ↑Sat May 04, 2024 8:19 pm
Yeah but if I do that I would be able to maintain the jump button and have some sort of auto jump and I don't want that
Then add a little state machine to prevent that:
little_state_machine.png (20.28 KiB) Viewed 1451 times
function love.load()
player.jumpingState = "isNotJumping"
end
function love.update()
if player.jumpingState == "isNotJumping" and paddy.isDown('a') then
player.jumpingState = "isJumping"
player.collider:applyLinearImpulse(0,-50000)
end
if player.jumpingState == "isJumping" and not paddy.isDown('a') then
player.jumpingState = "isNotJumping"
end
end