Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2D scene graph  (Read 2388 times)
0 Members and 1 Guest are viewing this topic.
Offline cookie

Junior Member


Medals: 1



« Posted 2013-05-04 10: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.
Offline gouessej
« Reply #1 - Posted 2013-05-04 12:42:13 »

Hi

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

Offline cookie

Junior Member


Medals: 1



« Reply #2 - Posted 2013-05-04 13: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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #3 - Posted 2013-05-04 14: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
Offline cookie

Junior Member


Medals: 1



« Reply #4 - Posted 2013-05-04 14: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.

Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #5 - Posted 2013-05-04 14: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 Smiley

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

Junior Member


Medals: 1



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

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

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


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

The overview for scene2d, libgdx's 2D scene graph, lists what it provides:
https://code.google.com/p/libgdx/wiki/scene2d
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.

Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #8 - Posted 2013-05-04 16: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
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #9 - Posted 2013-05-04 16: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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (37 views)
2014-07-18 06:55:21

Zero Volt (35 views)
2014-07-17 23:47:54

danieldean (28 views)
2014-07-17 23:41:23

MustardPeter (31 views)
2014-07-16 23:30:00

Cero (46 views)
2014-07-16 00:42:17

Riven (47 views)
2014-07-14 18:02:53

OpenGLShaders (36 views)
2014-07-14 16:23:47

Riven (36 views)
2014-07-14 11:51:35

quew8 (32 views)
2014-07-13 13:57:52

SHC (68 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!