Hi
I started the beginner tutorial a while ago and stumbled upon something i can’t fix. As the tutorial says, I made a few cubes but the thing which bothered me was the duplicate script, so I created a method which instantiates class fields Geometry playerx etc. and it actually creates them, shows them next to the blue cube from the SimpleApplication as i desired but when I want to update them somehow (e.g. rotate them), the game crashes and gives me a NullPointerException error. Any ideas?
Do I have to tinker with the AppState to make it work? To be honest I don’t understand the Appstate tutorial at all.
Thx for replies, Milson
Well compiled .class couldnt be readed (but .java file should)
yeh the appstate tutorial is a little confusing, at least for me, i try to avoid them, but I would say controls would be better suited for what you want to do here anyways, and they are much easier to use.
@milson I learned AppState (without tutorial) which gived me hard time but now got it working and it is just great!
If you can show us your code, so someone can check it?
Ok so here’s my method, it’s declared under class fields
and then I use it in simpleInitApp like this
but updating it in simple update (playa.rotate(tpf,0,0);) crashes the game :(
use
playa = new Geometry();
Cube(playa, new Vector3f(0,-3,0),0.5f, 0.5f, 0.5f, “zeh cube”, ColorRGBA.Magenta);
Cube method gets copy of that object (?? I though class objects are always references to the original), so when it creates new Geometry, it got lost when returning from method…I used C# long time so my java skills arent so much top in my memory yet (in C# these objects passed with ref/out)
So change your Cube() method that there is local Geometry geom=new … and return it.
I am new to Java myself and was also working with C# for almost a year.
I understand now the problem, thank you very much larda it works now.
Btw any ideas how could this be used with the appstate/control?
I learned AppState from rootappstate demo, you just create class which extends AppState, you add it and there is update() -method which
does what you want … I use this now on menu, game and when pressing esc, it opens menu again, and it seems to working well (never before
understanded what state machine means but now (if this is the same that state machine)).
You can however use Appstates what ever you want, when you come familiar that, I cant much help here because just learning myself this too.