Last active
August 30, 2018 20:15
-
-
Save vgebrev/5168925b97f1c239dfaca59b304d0f29 to your computer and use it in GitHub Desktop.
PICO-8 time based timer for animation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pico-8 cartridge // http://www.pico-8.com | |
version 16 | |
__lua__ | |
function _init() | |
timer = { elapsed = 0, last = time() } | |
circle = {} | |
circle.animation = { length = 0.25, elapsed = 0} | |
circle.color = 0 | |
end | |
function update_timer() | |
timer.elapsed = (time() - timer.last) | |
timer.last = time() | |
end | |
function update_circle() | |
circle.animation.elapsed += timer.elapsed | |
if (circle.animation.elapsed >= circle.animation.length) then | |
circle.color = (circle.color + 1) % 15 | |
circle.animation.elapsed = 0 | |
end | |
end | |
function _update() | |
update_timer() | |
update_circle() | |
end | |
function _draw() | |
cls(1) | |
circfill(63, 63, 32, circle.color) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment