Hello developers,
I have created guide for making scene manager in Love2d. Generally I do not write a tutorial. its not my profession and this is first tutorial I have written. So take a look and give feedback.
https://github.com/Janglee123/Love2dGui ... eneManager
[Guide] State Manager
[Guide] State Manager
Last edited by janglee on Thu Dec 27, 2018 4:41 am, edited 1 time in total.
Re: [Guide] Scene Manager
It's good, though the choice of the name is a bit unconventional. These are typically called states, rather than scenes, because the name 'scene' is typically used in the context of scene trees using for rendering, where nodes are normally connected in such way that if you e.g. rotate a node, then all of its children rotate with it. See e.g. viewtopic.php?f=5&t=85947
There are several libraries to handle game states, but I like how you expose it as something natural and straightforward to implement. It's uncommon to need a pre-made library in order to handle game states. There are some libraries that handle nested states, but I have never had a need for those, therefore what you explain should be good for most people. So good job on that.
The method you call 'reset', I call 'activate' because in my case, some states also need an event called 'deactivate', for example to stop sounds that may be still running. It would be a good idea to add an event that fires when exiting a state, for this reason.
Finally, you assume that no state uses any other love callbacks. Depending on the game, some of them will use other events (like 'textinput' if there is any text input, for example), and it's a good idea in general to check if the state function is defined before calling it.
There are several libraries to handle game states, but I like how you expose it as something natural and straightforward to implement. It's uncommon to need a pre-made library in order to handle game states. There are some libraries that handle nested states, but I have never had a need for those, therefore what you explain should be good for most people. So good job on that.
The method you call 'reset', I call 'activate' because in my case, some states also need an event called 'deactivate', for example to stop sounds that may be still running. It would be a good idea to add an event that fires when exiting a state, for this reason.
Finally, you assume that no state uses any other love callbacks. Depending on the game, some of them will use other events (like 'textinput' if there is any text input, for example), and it's a good idea in general to check if the state function is defined before calling it.
Re: [Guide] Scene Manager
I hear you.pgimeno wrote: ↑Wed Dec 26, 2018 11:46 am It's good, though the choice of the name is a bit unconventional. These are typically called states, rather than scenes, because the name 'scene' is typically used in the context of scene trees using for rendering, where nodes are normally connected in such way that if you e.g. rotate a node, then all of its children rotate with it. See e.g. viewtopic.php?f=5&t=85947
Thanks for suggestion. Naming is what I do worse than worse.pgimeno wrote: ↑Wed Dec 26, 2018 11:46 am The method you call 'reset', I call 'activate' because in my case, some states also need an event called 'deactivate', for example to stop sounds that may be still running. It would be a good idea to add an event that fires when exiting a state, for this reason.
Sorry, but I am not getting you. can you give me one more example ?pgimeno wrote: ↑Wed Dec 26, 2018 11:46 am Finally, you assume that no state uses any other love callbacks. Depending on the game, some of them will use other events (like 'textinput' if there is any text input, for example), and it's a good idea in general to check if the state function is defined before calling it.
Re: [Guide] State Manager
What you're attempting to build here is a state machine (not a scene or state 'manager'). The reason why you'd want to use this to 'manage your scenes' is because you need a mechanism to switch between different parts of your game: the main menu, the options menu, the actual game, etc, right?
LÖVE has only a single global state (one love.load, one love.draw, etc.), which why a more flexible construct is desirable. pgimeno's point (I presume) is that your implementation is a minimal building block for that, but it is lacking in several ways: It only covers load, update, and draw, but there is more to a global game state that needs multiplexing: updating, drawing, loading, key presses, text input, mouse movement and mouse buttons, etc. are all equally important events, but you're ignoring most of them.
It'd also come in handy to have well defined enter/exit points (transitions) between states: when going from game to settings, I don't want to reset the entire game; but I probably want to reset the game state when the game is over and the player goes back to the main menu. Only having 'resetState' is lacking flexibility.
Since the repo is called 'Love2dGuides', it's only fair to assume you only want to show a general direction on how it could be done and leave the rest up to the reader: if you aim to provide a useful framework to be used by anyone, this is not enough though.
LÖVE has only a single global state (one love.load, one love.draw, etc.), which why a more flexible construct is desirable. pgimeno's point (I presume) is that your implementation is a minimal building block for that, but it is lacking in several ways: It only covers load, update, and draw, but there is more to a global game state that needs multiplexing: updating, drawing, loading, key presses, text input, mouse movement and mouse buttons, etc. are all equally important events, but you're ignoring most of them.
It'd also come in handy to have well defined enter/exit points (transitions) between states: when going from game to settings, I don't want to reset the entire game; but I probably want to reset the game state when the game is over and the player goes back to the main menu. Only having 'resetState' is lacking flexibility.
Since the repo is called 'Love2dGuides', it's only fair to assume you only want to show a general direction on how it could be done and leave the rest up to the reader: if you aim to provide a useful framework to be used by anyone, this is not enough though.
Re: [Guide] Scene Manager
For example, if the love.textinput event is necessary in several states/scenes, this could be added:janglee wrote: ↑Thu Dec 27, 2018 12:46 pmSorry, but I am not getting you. can you give me one more example ?pgimeno wrote: ↑Wed Dec 26, 2018 11:46 am Finally, you assume that no state uses any other love callbacks. Depending on the game, some of them will use other events (like 'textinput' if there is any text input, for example), and it's a good idea in general to check if the state function is defined before calling it.
Code: Select all
function love.textinput(text)
if scenes[ currentScene ].textinput then
return scenes[ currentScene ].textinput(text)
end
end
Re: [Guide] State Manager
See also: https://github.com/love2d-community/awe ... -libraries
(state helpers / switchers)
(state helpers / switchers)
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Re: [Guide] State Manager
Thank you to all for suggestions. I will update guide with suggested thing.
Re: [Guide] State Manager
Yeah, I wrote this guide for beginners and I am only working to provide on guide not a module. Guide does not contains other functions because i want it simplest but I would like to add some of you mentioned as they are most use full and lacking in guide. Mostly beginners do state management in if-else statements. Another thing I used is love2d's file system to read directory because I saw in other game an array containing state name is used to load states. That is not good way to do because when we delete or add state we also have to edit it in array manually. But the approach show in guide do it itself. That is my two main point to create guide.grump wrote: ↑Thu Dec 27, 2018 1:29 pm What you're attempting to build here is a state machine (not a scene or state 'manager'). The reason why you'd want to use this to 'manage your scenes' is because you need a mechanism to switch between different parts of your game: the main menu, the options menu, the actual game, etc, right?
LÖVE has only a single global state (one love.load, one love.draw, etc.), which why a more flexible construct is desirable. pgimeno's point (I presume) is that your implementation is a minimal building block for that, but it is lacking in several ways: It only covers load, update, and draw, but there is more to a global game state that needs multiplexing: updating, drawing, loading, key presses, text input, mouse movement and mouse buttons, etc. are all equally important events, but you're ignoring most of them.
It'd also come in handy to have well defined enter/exit points (transitions) between states: when going from game to settings, I don't want to reset the entire game; but I probably want to reset the game state when the game is over and the player goes back to the main menu. Only having 'resetState' is lacking flexibility.
Since the repo is called 'Love2dGuides', it's only fair to assume you only want to show a general direction on how it could be done and leave the rest up to the reader: if you aim to provide a useful framework to be used by anyone, this is not enough though.
Who is online
Users browsing this forum: No registered users and 1 guest