I have two threads. One thread has an instance of myObjectManager. myObjectManager has a list of objects and a method for retrieving an object (public myObjectClass getObjectById (int ID))
I need the first thread to render the object in the list of myObjectManager objects, and the second thread to execute the game logic and move it around, etc.
Here is what I tried
//thread 1:
m = myObjectManager.getObjectById(100);
m.render();
//thread 2:
m = myObjectManager.getObjectById(100);
m.rotate( m.getRotation() + 5 ); //increment rotation value
However, it seems that thread 1 has an instance of the object without an updated rotation. When I run it, the rendered object does not rotate, but when I do the second thread, print its rotation value.
In C ++, I just want the getObjectById () function to return a pointer to an instance of myObjectClass, but I'm not sure what java does when I say "return myInstance"; How do I do something like this in java?
Sorry, I'm new to this language!
source
share