Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (756) Games in Android Showcase (229) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 2D scene graph  (Read 8166 times) 0 Members and 1 Guest are viewing this topic.

Junior Devvie

Medals: 1

 « Posted 2013-05-04 08:09:53 »

Hello forum,
how could a scene graph for a 2D game be implemented? I would choose an array list and store some sprites in there, but maybe it's not that simple.
gouessej
 « Reply #1 - Posted 2013-05-04 10:42:13 »

Hi

Do you really want to write your own scenegraph? I would use a tree as the main abstract data type.

Julien Gouesse | Personal blog | Website | Jogamp

Junior Devvie

Medals: 1

 « Reply #2 - Posted 2013-05-04 11:45:44 »

Yes, if it's not too complicated. In 3D a scene graph is used to implement an object hierarchy, but I'm not sure if it's useful in a simple Tetris or Super Mario style 2D game.
matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #3 - Posted 2013-05-04 12:03:58 »

Tetris is a very good example.

Imagine a scene graph tree:
You have your tetris objects in your tree. They are composed of (4) Blocks. If you move the top node, your blocks move.

Here is an example of such a tree:

root
/  \
/    \
/      \
/        \
/          \
/            \
Tetris "L"            Tetris Pipe
/   |   |  \          /   |   |   \
offsets: (0,0)(0,1)(0,2)(1,2)   (0,0)(0,1)(0,2)(0,3)

So if you rotate or move a tetris object, it's children rotate, if you move the tetris objects, the children move.

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github

Junior Devvie

Medals: 1

 « Reply #4 - Posted 2013-05-04 12:21:56 »

Thanks. You are right, Tetris blocks are composed of multiple graphical objects, but would a scene graph still make sense if you just had to catch some graphical objects that fall from above? In this case, I don't see any hierarchy.

matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #5 - Posted 2013-05-04 12:25:38 »

Thanks. You are right, Tetris blocks are composed of multiple graphical objects, but would a scene graph still make sense if you just had to catch some graphical objects that fall from above? In this case, I don't see any hierarchy.

Yeah. Of course there are examples, where there isn't any hierarchy... this is one of those examples.

But generally I think they are cool

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github

Junior Devvie

Medals: 1

 « Reply #6 - Posted 2013-05-04 14:09:06 »

If there's not hierarchy, what sense does a scene graph make in this case? I haven't understood this yet.
Nate

« JGO Bitwise Duke »

Medals: 167
Projects: 4
Exp: 14 years

Esoteric Software

 « Reply #7 - Posted 2013-05-04 14:14:21 »

The overview for scene2d, libgdx's 2D scene graph, lists what it provides:
If you have no hierarchy at all, it still helps with drawing and hit detection for rotated/scaled actors. The action system might also be useful. Also note the second to last paragraph that talks about model-view coupling.

matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #8 - Posted 2013-05-04 14:17:15 »

Each actor draws in its own unrotated and unscaled coordinate system where 0,0 is the bottom left corner of the actor.

In that sense there is a hierarchy.

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Nate

« JGO Bitwise Duke »

Medals: 167
Projects: 4
Exp: 14 years

Esoteric Software

 « Reply #9 - Posted 2013-05-04 14:28:23 »

Yes, a hierarchy consisting of one level (the root group with actor (non-group) children). This is also known as a list. :p

It is convenient for actors to think in their own unrotated and unscaled coordinate system, where 0,0 is the bottom left corner and width,height is the upper right corner (you can use y-down with scene2d if you want, but then some scene2d.ui widgets won't work (scene2d.ui is a UI library built on top of scene2d)). It makes drawing and hit detection easier.

Pages: [1]
 ignore  |  Print

 DesertCoockie (56 views) 2018-05-13 18:23:11 nelsongames (88 views) 2018-04-24 18:15:36 nelsongames (78 views) 2018-04-24 18:14:32 ivj94 (763 views) 2018-03-24 14:47:39 ivj94 (95 views) 2018-03-24 14:46:31 ivj94 (647 views) 2018-03-24 14:43:53 Solater (108 views) 2018-03-17 05:04:08 nelsongames (189 views) 2018-03-05 17:56:34 Gornova (430 views) 2018-03-02 22:15:33 buddyBro (1090 views) 2018-02-28 16:59:18
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org