Hi
i am New to Jmonkey and i have problems with appstate
well i want to move a caractere from appstate but when i do that i get a fixed postion version of the caractere and another when that work as i need 2
i have searched google and forums here and i didn’t find an answer
and what confuse me more the same code in the main class work perfectly
@author normenhansen
*/
public class Main extends SimpleApplication {
Coiffeure_chaise chaise = new Coiffeure_chaise(1);
public static void main(String[] args) {
Main app = new Main();
app.start();
}
public Spatial scene;
public Spatial[] model2 = new Spatial[10];
public int i = 0;
public Quaternion R = new Quaternion();
private Node coiffeur;
private AnimControl control;
private AnimChannel channel;
private float cpt;
private long currentTime;
private long totalTime;
/*********** this the part where i do the attechement of appstate :/ ***/
Man t = new Man();
t.initialize(stateManager, this);
stateManager.attach(t);
t.setEnabled(true);
}
@Override
public void simpleUpdate(float tpf) {
/******** this is the same code i use in appsatate and it works in main *********/
first thank you for replaying
what i can say that i already looked to the link before but i can’t figure it out
i am starting to think that i am using the wrong tool ( appstate ) my goal is to control this spatial with its animation as a thread to make each caracter do his function
before i post anything here i make sure that this is my last option so thank for the motivation speach
I have tried costum control its the same problem it dosent update correctly it keep a clone of the model and move another one like you can see in the picture i shared
In the simpleInitApp() of the Main class you call the following code at the end:
Man t = new Man(); // you create a new instance, all fine so far ...
t.initialize(stateManager, this); // what the hell shall that be??? NO! REMOVE THIS LINE!
stateManager.attach(t); // this is the way to go! ONLY THIS !!!!!!!!!
t.setEnabled(true); // isn't really neccessary, but okay ...
Let’s have a look at your initialize method:
public void initialize(AppStateManager stateManager, Application app) {
[ ... some code ... ]
System.out.println("Here i am");
initialized = true;
simpleInitApp(); // in this method you create your model and attach it to the scene!
}
Your simpleInitApp() method does the following:
public void simpleInitApp() {
System.out.println("Here i am");
// the global field Coiffeur gets a value!!!
coiffeur = (Node) assetManager.loadModel("Models/Man/coiffeur.j3o");
coiffeur.setMaterial(assetManager.loadMaterial("Materials/material.j3m"));
rootNode.attachChild(coiffeur); // is attached to scene
coiffeur.rotate(0, 2, 0);
coiffeur.updateGeometricState(); // not neccessary in newer jmes
totalTime = System.currentTimeMillis();
}
Maybe you got it: Did you ask yourself why you see 2 models? Here is the answer, because you created 2 models (instances) and attached them both to the scene!
time: t.initialize(stateManager, this); this calls simpleInitApp() of your AppState which in turn attaches a model to the Scene and gives a value to the global field Coiffeur.
time: stateManager.attach(t) here the initialize method is called from the render thread of jme. The same happens like in 1. But now the global field Coiffeur is “overriden”. You only have access to the latest created model.
I hope it is clear now, what you are doing wrong here!
But I really recommend you to read the wiki (about app states and controls and where they are used) and if you did already, do it again and make sure you really understand what you are reading.