Countdown when resuming from Pause

I figured out a much simpler way to do this, leveraging playdate.wait():

local gfx <const> = playdate.graphics

function playdate.gameWillResume()

	-- save off the current playdate.update so we can restore it at the end of the countdown
	local saveOffUpdate = playdate.update
	
	playdate.update = 
	function()	
		
		-- draw the countdown
		gfx.clear()
		gfx.drawText( "3", 200, 120 )
		playdate.wait( 1000 )
		gfx.clear()
		gfx.drawText( "2", 200, 120 )
		playdate.wait( 1000 )
		gfx.clear()
		gfx.drawText( "1", 200, 120 )
		playdate.wait( 1000 )
		gfx.clear()
		
		-- restore the "real" playdate.update
		playdate.update = saveOffUpdate

	end
		
end
4 Likes