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.
About scene-graphs and parenting.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Citizen
- Posts: 63
- Joined: Tue Jan 14, 2014 11:03 pm
Re: About scene-graphs and parenting.
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)
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)
- slime
- Solid Snayke
- Posts: 3131
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: About scene-graphs and parenting.
Scene graph hierarchies are effectively push/translate/etc/pop, behind the scenes.
Re: About scene-graphs and parenting.
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.
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.
Who is online
Users browsing this forum: Ahrefs [Bot] and 42 guests