Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Documents Playdate architecture patterns: push-down state machine, screen lifecycle hooks, module separation, and the 30 FPS update budget.
41% 77%+36 ptsof test cases passed
Passed 17 of 22 test cases with the skill, and 9 of 22 without it.
3 of 3 safety checks passed
Not used yet
The recommended pattern for Playdate games is a push-down automaton managing a stack of screens. This enables nested state — pausing to show a menu without destroying the game state beneath.
-- src/core/StateMachine.lua
StateMachine = {}
StateMachine.__index = StateMachine
function StateMachine.new()
return setmetatable({ stack = {} }, StateMachine)
end
-- Push a new state; pause the current one
function StateMachine:push(state)
local current = self.stack[#self.stack]
if current and current.onPause then current:onPause() end
table.insert(self.stack, state)
if state.onEnter then state:onEnter() end
end
-- Pop current state; resume the one below
function StateMachine:pop()
local current = table.remove(self.stack)
if current and current.onExit then current:onExit() end
local next = self.stack[#self.stack]
if next and next.onResume then next:onResume() end
end
-- Replace current state (no stack growth)
function StateMachine:swap(state)
local current = table.remove(self.stack)
if current and current.onExit then current:onExit() end
table.insert(self.stack, state)
if state.onEnter then state:onEnter() end
end
function StateMachine:update()
Next to this one in the catalogue, plus more from the same author.