Instantiate Geometry objects out of simpleInitGame() method


is there a way to istantiate Geometry objects out of simpleInitGame() method?

If I try, a NullPointerException occurs.

I would like to make a kind of addItem(Geometry g) method that lets me add new items to a 3d ambient;this means that

I don't know a priori the number and the kind of shapes will populate my scene.

Thank you 

It's two days I know jmonkey:it's not yet in my intentions to make a whole game; I don't think I'm able to :slight_smile:

I'm still exploring jmonkey basic features.


This is the purpose of the simpleInitGame is to provide the right place-in-time to initialize your spatials.  The reason it's throwing a NullPointerException is because the display has to be initialized before you can instantiate graphical objects because it needs to reference that in order to "come into being".  If you need to dynamically add things after the game has started it shouldn't be a problem outside of the initgame so long as initgame has executed first.


Now are you trying to instantiate them pre or post init?  If it's before I would understand the NullPointer because the Graphics has to be instantiated first, but if it's post it would be something else.  What exactly is the exception you're seeing?


I tried to istantiate objects before init method;

I though I had to create the whole structure of the ambient before beginning rendering.

So what should I do ?

Thank you

In all honesty, what you should do is stop using SimpleGame and create your own game type. SimpleGame was designed to facilitate quick demo/test writing. But you have moved beyond what it can do for you.

Mojo, I disagree, I think he's still in a pretty optimal position (particularly learning-wise) to use SimpleGame.  Once he has had success and is actually prepared to write a game then yes I definitely agree that SimpleGame should be kicked out.  I really like SimpleGame for learning, it provides a good way to test everything before I actually get to the point of putting it in my game.


Well: could I put Items to render in an istance Vector of the class overrides SimpleGame?

The pattern to follow is not very clear to me  :expressionless:

Thank you  :slight_smile:

I would highly recommend looking at some of the examples as that will give you a good idea of how to write games in jME.