2dengine / love.scene

Small scene graph library written for the LÖVE framework using pure Lua
MIT License
14 stars 1 forks source link

Question about update(dt) function #4

Open FlexTheProgrammer opened 1 year ago

FlexTheProgrammer commented 1 year ago

Have you considered adding a view:update(dt) function that would call an update on all of the nodes in the view hierarchy? (similar to draw). That would make writing gameplay code a lot easier. Mainly because that would allow encapsulating given node gameplay code in its update function (state machines, etc.) without the need to store specific nodes as variables and call updates explicitly (you would call view: update(dt), and it would take care of that for you)

2dengine commented 1 year ago

Hello and thank you so much for the feedback. From a design standpoint I would argue that it is good to have a clear and distinct separation ("decoupling") between your rendering code from your gameplay code. One of the strengths of the scene graph is that it moves the drawing code away from your game logic. This way you can disable love.scene and run your logic/simulation as a "game server" without any rendering at all. My recommendation is to make sure that your state machine's code does NOT depend on love.scene

There are exceptions to the above-mentioned rule. For example, if you are building a Generic User Interface or GUI then your different components will need to handle both logic, drawing and input in one file or class. At this time the scene graph is not very well suited for building user interfaces.

Happy new year! Ivan