My implementation of game states library
Posted: Fri May 08, 2020 9:00 pm
Hello dear Love2d community. Some time ago I've created a small states.lua lib for personal use and used that in every single of my project afterwards. Thought I might as well publish it separately on github and share with people in case they find it useful.
Here's the github link: https://github.com/Spellsweaver/States
I would be really happy if it turns out useful for someone besides me, or if someone provides useful feedback on the code.
How to use
In main.lua
states = require("states")
in love.load() call states.setup()
From now on, states library will redirect love2d callbacks from your main.lua to state files
Each state file should be located in "states/" directory and return a table of callbacks that correspond to love2d callbacks
If you want your callbacks to be state-independant, keep them in your main.lua. This way states library will not redirect them to states.
If you want a callback to have both state-dependant and state-independant part,
keep it in main.lua and call states.(callback name) within love 2d callback
To switch states (you should probably do this immediately after initialising) use states.switch(filename,params)
Filename is a name of your state file, while params is a table that will be caught by .open callback within according state file
Through params you can transfer data to your state files conveniently
Here's the github link: https://github.com/Spellsweaver/States
I would be really happy if it turns out useful for someone besides me, or if someone provides useful feedback on the code.
How to use
In main.lua
states = require("states")
in love.load() call states.setup()
From now on, states library will redirect love2d callbacks from your main.lua to state files
Each state file should be located in "states/" directory and return a table of callbacks that correspond to love2d callbacks
If you want your callbacks to be state-independant, keep them in your main.lua. This way states library will not redirect them to states.
If you want a callback to have both state-dependant and state-independant part,
keep it in main.lua and call states.(callback name) within love 2d callback
To switch states (you should probably do this immediately after initialising) use states.switch(filename,params)
Filename is a name of your state file, while params is a table that will be caught by .open callback within according state file
Through params you can transfer data to your state files conveniently