Page 2 of 5

Re: love.scene (yet another scene graph library)

Posted: Mon Jan 04, 2021 12:07 pm
by yetneverdone
Hmm that would be harder as camera has been integrated in my game in a lot of scenes. I'll try moving to this library and do more test

Re: love.scene (yet another scene graph library)

Posted: Tue Jan 26, 2021 11:01 pm
by ivan
Just pushed an update featuring full HTML documentation:
https://2dengine.com/?p=scene

Re: love.scene (yet another scene graph library)

Posted: Fri Mar 25, 2022 7:40 pm
by cystedtwister
I was just about to sit down and start working out a scene manager, thought I'd see if the work's already been done. I just perused the HTML docs for your Love.scene, @ivan, and I am impressed. It looks exactly like what I'm after. So complete, as well! I'm grateful you decided to put it up for other's to use, and documented it so well! I will definitely be checking it out.

Re: love.scene (yet another scene graph library)

Posted: Thu Mar 31, 2022 6:01 pm
by ivan
Thank you. I use this library in almost all of my Love2d games and will be happy to help if you encounter any issues or if you have questions.

Re: love.scene (yet another scene graph library)

Posted: Wed Nov 16, 2022 1:00 am
by yetneverdone
ivan wrote: Thu Mar 31, 2022 6:01 pm Thank you. I use this library in almost all of my Love2d games and will be happy to help if you encounter any issues or if you have questions.
Hi, looking to try this lib again, looking at the source code, it doesn't seem to handle love.graphics.print and rectangle, and other primitives. What approach would one use to draw those using this lib?

Re: love.scene (yet another scene graph library)

Posted: Wed Nov 16, 2022 1:51 pm
by ivan
yetneverdone wrote: Wed Nov 16, 2022 1:00 am Hi, looking to try this lib again, looking at the source code, it doesn't seem to handle love.graphics.print and rectangle, and other primitives. What approach would one use to draw those using this lib?
Hello and thank you for the question.

Here is how to do text:

Code: Select all

local font = love.graphics.getFont()
local text = love.graphics.newText(font, "Hello world!")

local view = love.scene.newView()
local sprite = view:newSprite(0, 0)
sprite:setGraphic(text)
Here is how to do a rectangle:

Code: Select all

local rect = { {0,0}, {100,0}, {100,100}, {0,100} }
local mesh = love.graphics.newMesh(rect, "fan", "static")

local view = love.scene.newView()
local sprite = view:newSprite(0, 0)
sprite:setGraphic(mesh)
The strength of the scene graph is that once it is generated you can draw it without running any additional code.
This is usually faster and cleaner compared to using love.graphics.draw:

Code: Select all

function love.draw()
  view:draw()
end
You also have a number of functions like "localToWindow" and "windowToLocal" that allow you to transform the mouse position and get the local position relative to each sprite inside the scene graph.
It is very easy to query the scene graph and find which sprite you have clicked on.

These are standard features to 2D scene graphs (see ActionScript, PIXI.js, etc).
love.scene documentation: https://2dengine.com/?p=scene

Re: love.scene (yet another scene graph library)

Posted: Wed Nov 16, 2022 2:30 pm
by ivan
Regarding your previous question on cameras.

Here is how to offset the camera/scene to 200,100:

Code: Select all

view:setScene(200, 100)
The position specified in "setScene" is always drawn in the center of the view(port).
Offsetting the "scene" is basically the same thing as moving the camera.
I agree that the function name "setScane" is somewhat misleading.

Re: love.scene (yet another scene graph library)

Posted: Wed Nov 16, 2022 4:07 pm
by yetneverdone
I see, thanks for the explanations. I was hoping of using love.graphics.rectangle/print instead of generating text and mesh objects. I can manage with those still.

Do you recommend using camera node as the parent/root node of all other nodes just like how it is structured in Unity and Godot (i think?)

Oh and another for confirmation, would the child node inherit the transformation of the parent node?

Re: love.scene (yet another scene graph library)

Posted: Wed Nov 16, 2022 5:39 pm
by ivan
yetneverdone wrote: Wed Nov 16, 2022 4:07 pm I see, thanks for the explanations. I was hoping of using love.graphics.rectangle/print instead of generating text and mesh objects. I can manage with those still.
It is a little bit counter-intuitive at first.
yetneverdone wrote: Wed Nov 16, 2022 4:07 pm Do you recommend using camera node as the parent/root node of all other nodes just like how it is structured in Unity and Godot (i think?)
Yes. Also, you can have multiple view objects rendering the same scene. I used this method to build the split screen feature in the game Skullmaster's Arena.
I am not sure how it works in Unity or Godot.
yetneverdone wrote: Wed Nov 16, 2022 4:07 pm Oh and another for confirmation, would the child node inherit the transformation of the parent node?
Yes! If you move the parent node all of the child nodes will be offset too.

Re: love.scene (yet another scene graph library)

Posted: Thu Nov 17, 2022 1:13 am
by yetneverdone
Awesome. Now im convinced to go with it. Just got to think how i will incorporate this with ecs 🤔