Hi guys I have been using this code to make a simple ship:
[java]
package mygame;
import com.jme3.asset.AssetManager;
import com.jme3.input.InputManager;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
public class Player {
public Spatial b;
Main game;
AssetManager assetManager;
InputManager inputManager;
Node rootNode;
Player(Main aThis){
game = aThis;
rootNode = game.getRootNode();
assetManager = game.getAssetManager();
inputManager = game.getInputManager();
b = (Spatial) assetManager.loadModel("Models/Garbage Pod.j3o");
System.out.println(b.getLocalTranslation());
Material mat_lit = new Material( assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat_lit.setTexture("m_DiffuseMap", assetManager.loadTexture("Textures/GPod.tga"));
mat_lit.setFloat("m_Shininess", 10f); // [0,128]
b.setMaterial(mat_lit);
rootNode.attachChild(b);
initKeys(); // load my custom keybinding
}
/** Custom Keybinding: Map named actions to inputs. /
private void initKeys() {
/* You can map one or several inputs to one named mapping. /
inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_LEFT));
inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_RIGHT));
inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_UP));
// left click!
/* Add the named mappings to the action listeners. /
inputManager.addListener(analogListener, new String[]{"Left", "Right", "Up"});
}
/* Use this listener for continuous events /
private AnalogListener analogListener = new AnalogListener() {
public void onAnalog(String name, float value, float tpf) {
if (name.equals("Right")) {
b.rotate(0, -5tpf ,0);
}
if (name.equals("Left")) {
b.rotate(0, 5*tpf,0);
}
if (name.equals("Up")) {
}
}
};
}[/java]
It has been working for a while now. I dont remember making ANY changes to this code but all of the sudden i am getting this error:
Jan 23, 2011 3:21:13 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.ClassCastException: com.jme3.scene.Node cannot be cast to com.jme3.scene.Geometry
at mygame.Player.(Player.java:46)
at mygame.Main.simpleInitApp(Main.java:54)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:186)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:134)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:188)
at java.lang.Thread.run(Thread.java:662)
I know what the error means but I have no clue what could be causing it, Since this code has worked for me before. Does anyone see any errors? I sure couldnt after looking over it so many times :S.