onExpire

.onExpire() { ... }

Allows you to set an action that is performed, when this timer expires.

This can be called multiple times to set multiple expire callbacks.

This Timer object is returned to allow chaining.

color = :red
timer = new Timer( 2000 ).onExpire() do
    color = :green
end

onEachFrame() do
    fill( :black )
    
    size = 50 * timer.getPercent()
    setColor( color ) do
        fillRect( 100, 100, size, size, true )
    end
end

.onExpire( action )

This also adds an action, but takes a function object rather then a block.

color = :red

changeColor = def()
    color = :green
end

timer = new Timer( 2000 ).onExpire( changeColor )

onEachFrame() do
    fill( :black )
    
    size = 50 * timer.getPercent()
    setColor( color ) do
        fillRect( 100, 100, size, size, true )
    end
end

See also

cancelExpires