love.scene (yet another scene graph library)

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

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

Post 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
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

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

Post by ivan »

Just pushed an update featuring full HTML documentation:
https://2dengine.com/?p=scene
cystedtwister
Prole
Posts: 1
Joined: Fri Mar 25, 2022 7:33 pm

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

Post 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.
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

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

Post 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.
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

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

Post 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?
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

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

Post 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
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

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

Post 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.
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

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

Post 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?
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

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

Post 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.
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

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

Post by yetneverdone »

Awesome. Now im convinced to go with it. Just got to think how i will incorporate this with ecs 🤔
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 5 guests