About scene-graphs and parenting.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
gianmichele
Citizen
Posts: 63
Joined: Tue Jan 14, 2014 11:03 pm

About scene-graphs and parenting.

Post by gianmichele »

Hi all,

I'm constantly coming back here for questions and advice as this is such a friendly space. My problem today is about scene graph and parent-child relationship.

In "another framework" I can add an object as a child of another one. This way I can simply move, rotate or scale the parent object and the child follows accordingly.
While I have an idea of how to implement something like this in love, using push, pop and transformations, I would love to know how you guys approach a situation like this in a more "lovely" fashion.

Thanks in advance.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: About scene-graphs and parenting.

Post by arampl »

Hi!
There are no parent-child relationship mechanism in LÖVE's API nor in Lua itself. Maybe you can search for third-party library which implements this.
Or you can implement it yourself using nested tables & recursion to update children's properties whenever corresponding parent's property changes.
Note that in Lua children knows nothing about their parent so they should also have property pointing to upper table (in case you need to notify parent about children changes).

some resources:
1. I've found one interesting discussion by tesselode here: http://stackoverflow.com/questions/1348 ... alue-is-in.
2. "Lua Game Development Cookbook" describes such thing for window's hierarchy (chapter 6)
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: About scene-graphs and parenting.

Post by slime »

Scene graph hierarchies are effectively push/translate/etc/pop, behind the scenes.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: About scene-graphs and parenting.

Post by ivan »

From a practical standpoint I would like to point out that scene graphs are not very useful in 2d games.
Scene graphs IMO are useful when you have STATIC geometry that you want to cull, draw or query.

Generally the functionality you are describing can be achieved using matrices/affine transformations:
https://code.google.com/p/lua-files/wiki/affine2d

Here is my poor attempt at scene graphs (without matrices):
https://bitbucket.org/itraykov/utils/sr ... rt/cst.lua

But again, you rarely need this in a 2D game.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 42 guests