[Various Questions] Main Topic: Custom Quad


I've written a tiny game which i already have created a Swing-Frontend for and now want to make it look cool, via the JMonkeyEngine.

One of my problems is, that I don't grasp the whole concept behind the engine. Somehow there's this Renderer that does most of the stuff, so it needs to be accessible in every single of my graphical components. Well, ok, so I made my subclass of SimpleGame a Singleton that provides anything needed. Most tutorials are very limited (they only use a single class) and thus are not well structured (imho at least). I doubt this singleton approach of making the renderer (and system stuff) available to my graphical components is a best practice. Some advice on that would be appreciated.

Also, in my Swing-Frontend, I have various panels which contain a GameState member (which has nothing to do with Graphics, but just keeps track of the game), which are just made visible or invisible depending on user-interaction and game events. I want to reproduce this the closest possible, so my plan is to create some custom Nodes for every panel I have in Swing, containing the necessary GameState, GameEventHandling interface and the graphical components. What do you think about that?

[Main problem]

At the moment I am trying create a QuadComponent that automatically keeps track of itself and changes textures when its state change. By "state" I mean something defined in the logic of the game, which will be a member variable of the QuadComponent. Now I can't find the proper way for the quad to keep track of itself, e.g. change its texture, recognize mouse-intersection asf. I don't want to do this in some global context (like in the game class), but rather locally for every graphical component. Can you please hint me on how to do that? Sample code would be great!

I hope you understand my "not so poor but yet not good enough"-english and have a good day,


For better understanding, here is some pseudocode of what I want to achieve:

public class QuadComponent extends Quad implements MouseIntersectionListener
    /*...snip ...*/
    public void onMouseIntersection(MouseIntersectionEvent evt)
         //set another texture here

Thanks to a lil help from Mindgamer on IRC, I was able to solve all my problems.

1.) I realized I could access most essential system components in a static context (DisplaySystem.getDisplaySystem() etc.)

2.) I realized one could simply overwrite the onDraw method of a Node to make graphical components behave more like swing components in terms of drawing.

3.) I just built a Pickable interface and a Picker class, which contains a method to collect all picks, determie whether they implement Pickable and then call a method like onMouseOver. I call this method on every update of the game-subclass (and will later on call it in GameStates).