Bottons activating when I maintain them on touchscreen

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
snibo
Prole
Posts: 23
Joined: Sat May 04, 2024 6:56 am

Bottons activating when I maintain them on touchscreen

Post by snibo »

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

Code: Select all

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.

Video to make it clear
https://youtu.be/c2x9fR-drg8?si=wUxudQqoxNQAanPh

Note: for the buttons I am using a library called paddy and I don't really want to change a lot of stuff in it because I am scared of breaking stuff :?
User avatar
BrotSagtMist
Party member
Posts: 659
Joined: Fri Aug 06, 2021 10:30 pm

Re: Bottons activating when I maintain them on touchscreen

Post by BrotSagtMist »

Putting this in the touchpress callback looks like an error to me.
Put this in the update loop instead.
obey
snibo
Prole
Posts: 23
Joined: Sat May 04, 2024 6:56 am

Re: Bottons activating when I maintain them on touchscreen

Post by snibo »

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
Xugro
Party member
Posts: 114
Joined: Wed Sep 29, 2010 8:14 pm

Re: Bottons activating when I maintain them on touchscreen

Post by Xugro »

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
little_state_machine.png (20.28 KiB) Viewed 1451 times
This could look something like this:

Code: Select all

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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests