Hi all, Im new here.
Im followed the “Hello animation tutorial” with a model that I created, but its giving me an error when I add a listener to the control
here is the line code:
[java]control.addListener(this);[/java]
The code is practically the same of “Hello Animation”. Could anyone tell me what it must be?
Here is the error:
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at com.teste.GameTeste.simpleInitApp(GameTeste.java:46)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:722)
here is my full code
[java]import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import com.jme3.animation.LoopMode;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import sun.swing.PrintColorUIResource;
public class GameTeste extends SimpleApplication
implements AnimEventListener{
private AnimChannel channel;
private AnimControl control;
Node player;
public static void main(String[] args) {
GameTeste app = new GameTeste();
app.start();
}
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.LightGray);
initKeys();
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
rootNode.addLight(dl);
player = (Node) assetManager.loadModel(“Models/Cube.mesh.xml”);
player.setLocalScale(0.5f);
rootNode.attachChild(player);
control = player.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.setAnim(“stand”);
}
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
if (animName.equals(“stand”)) {
channel.setAnim(“rotateX”, 0.50f);
channel.setLoopMode(LoopMode.DontLoop);
channel.setSpeed(1f);
}
}
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
// unused
}
/** Custom Keybinding: Map named actions to inputs. */
private void initKeys() {
inputManager.addMapping(“rotateX”, new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(actionListener, “rotateX”);
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals(“rotateX”) && !keyPressed) {
if (!channel.getAnimationName().equals(“rotateX”)) {
channel.setAnim(“rotateX”, 0.50f);
channel.setLoopMode(LoopMode.Loop);
}
}
}
};
}[/java]