invert

.invert()

This inverts how far along this timer is, along it's time towards being expired. So if two thirds of this Timer's duration has been expired, then this will be reset to just one third.

If this Timer is fully expired, then this does the same as calling 'reset'.

Note that calling 'invert' will cancel all of the expiry callbacks.

/* 
 * Slowly fade in and out to pink.
 * It swaps direction when the user presses a key.
 */

// a ten second timer
timer = new Timer( 5_000 )
fadeIn = true

onEachFrame() do
    fill( :black )
    
    if fadeIn
        fill( :pink, timer.getPercent() )
    else
        fill( :pink, timer.getPercentLeft() )
    end
    
    if getControls().isKeyPressed()
        timer.invert()
        fadeIn = not fadeIn
    end
end

See also

reset