On button release (cool down / decelerate)

Before I keep cracking on... is this an ok approach to create a decelerate function and/ or a cool down


function playdate.update()
    playdate.timer.updateTimers()
    gfx.sprite.update()  

    if playdate.buttonIsPressed( playdate.kButtonUp ) then
        if (thrustSpeed < maxSpeed)
        then 
            thrustSpeed += 1
        end
        print (thrustSpeed)
    end

    if playdate.buttonJustReleased( playdate.kButtonUp ) then

        local function timerCallback()
            if (thrustSpeed > 0)
            then
                thrustSpeed -= 1
                print (thrustSpeed)

            end
            if (thrustSpeed == 0)
            then
                keyTimer:remove()
            end
          
        end       
        keyTimer = playdate.timer.keyRepeatTimer(timerCallback)

    end

end

Why do you need the timer? Why not put the decrease in the else of the buttonIsPressed?

2 Likes

Oh good shout - thank you