Skip to content

Instantly share code, notes, and snippets.

@vgebrev
Last active August 30, 2018 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgebrev/5168925b97f1c239dfaca59b304d0f29 to your computer and use it in GitHub Desktop.
Save vgebrev/5168925b97f1c239dfaca59b304d0f29 to your computer and use it in GitHub Desktop.
PICO-8 time based timer for animation example
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