Animation, Cutscene & Coroutine (Pico-8)

Want to spice up your game with animated scene between bouts of gameplay? Cutscenes are uncommon on small platforms like Pico-8. There’s no room for full motion video, so a scene must be described in code or with some kind of cutscene engine. This is made much easier with a Lua feature added in Pico-8 v0.1.6: coroutines. - Coroutines

To run a coroutine, you call coresume(). Inside of the coroutine, you can call yield() to pause the coroutine and return from the coresume() call. Then when you call coresume() with that coroutine again, it will continue from the last yield statement called.

Example of a dialog waiting button press

function dialog()
	print("hello")
	yield()               --pause
	print("world")
	yield()               --pause
	print("how are you?")
end

c = cocreate(dialog)

function _update()
	if btnp(4) then 
		coresume(c) 
	end
end

Animation

see also

Written on October 28, 2023, Last update on October 28, 2023
coroutine lua pico8