Re: Separate state files
Posted: Wed Feb 22, 2017 12:36 pm
Yeah, with a stack a library is starting to make sense. I think most libraries are not meant to handle multiple states at once, even on a stack (which is why i called st8 'double stacked'), but afaik jasocos does. His explanations of what he did sort of inspired st8.lua, and I bet he had the problem of up/down ordering too.airstruck wrote: ↑Wed Feb 22, 2017 8:33 amThe thing I like about your solution is the ability to propagate some callbacks upward (drawing) and others downward (input). I'm not sure how the others handle that. If you don't have a lot of layers of stuff, though, maybe just a floating pause menu or something, you don't really even need a stack, you can just have your pause state hold a reference to the game state and have it draw your game state before it draws itself. If you don't need a stack, you probably don't really need a library either. Should be easy enough to have something like "game.activeState" and set that to whatever state instance you want.s-ol wrote:i have my own on github too but I think you really dont need it.
a different way to solve it that I somehow only just realized would be to do it with a node-style callback argument:
Code: Select all
OverlayingMenu:update(propagate, dt)
-- update menu
propagate(0.1 * dt) -- slow down underlying state
end
OverlayingMenu:draw(propagate)
propagate() -- draw underlying state first
-- draw menu
end
OverlayingMenu:keypressed(propagate, key)
if key == "up" then
...
else
propagate(key) -- pass remaining keys on
end
end
Code: Select all
OverlayingMenu:draw(propagate)
lg.setCanvas(canvas)
propagate() -- lower state needs to care for the current canvas of course
lg.setCanvas()
lg.setColor(255, 255, 255, 100)
lg.draw(canvas)
end