Have I put everything in the right place? Thank you
error
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.GameRunningState.initialize(GameRunningState.java:79)
at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:251)
at com.jme3.app.state.AppStateManager.update(AppStateManager.java:281)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:239)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)
**GameRunningState class**
package mygame;
import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.asset.AssetManager;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.control.CharacterControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.input.ChaseCamera;
import com.jme3.input.FlyByCamera;
import com.jme3.input.InputManager;
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.light.PointLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Node;
/**
*
* @author yemibob
*/
public class GameRunningState extends AbstractAppState implements
ActionListener, AnimEventListener {
private ViewPort viewPort;
private Node rootNode;
private Node guiNode;
private AssetManager assetManager;
private SimpleApplication app;
public InputManager inputManager;
private Node localRootNode = new Node("Game RootNode");
private Node localGuiNode = new Node("Game GuiNode");
public AnimChannel animationChannel;
public AnimControl animationControl;
public ChaseCamera chaseCam;
public Node player;
public Node Scene;
public CharacterControl character;
public BulletAppState bulletAppState;
public Camera cam;
public FlyByCamera flybyCamera;
public BulletAppState bulletAppState;
public AppStateManager stateManager;
// track directional input
public boolean left = false, right = false, up = false, down = false;
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
this.app = (SimpleApplication) app;
this.rootNode = this.app.getRootNode();
this.viewPort = this.app.getViewPort();
this.guiNode = this.app.getGuiNode();
this.assetManager = this.app.getAssetManager();
this.inputManager = this.app.getInputManager();
this.bulletAppState = this.stateManager.getState(BulletAppState.class);
inputManager.setCursorVisible(true);
this.app.getFlyByCamera().setDragToRotate(false);
rootNode.attachChild(localRootNode);
guiNode.attachChild(localGuiNode);
//TODO: initialize your AppState, e.g. attach spatials to rootNode
//this is called on the OpenGL thread after the AppState has been attached
bulletAppState = new BulletAppState();
//bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);
PhysicsTestHelper.createPhysicsTestWorld(rootNode,
assetManager, bulletAppState.getPhysicsSpace());
Scene = (Node) assetManager.loadModel ("Models/Hotelroom/Hotelroom.j3o");
Scene.addControl(new RigidBodyControl(0));
localRootNode.attachChild(Scene);
bulletAppState.getPhysicsSpace().addAll(Scene);
PointLight lamp = new PointLight();
lamp.setPosition(Vector3f.ZERO);
lamp.setColor(ColorRGBA.White);
localRootNode.addLight(lamp);
localRootNode.attachChild(Scene);
/** A white, directional light source */
DirectionalLight sun = new DirectionalLight();
sun.setDirection((new Vector3f(1f, 1f, 1f)).normalizeLocal());
sun.setColor(ColorRGBA.White);
localRootNode.addLight(sun);
localRootNode.attachChild(Scene);
player = (Node) assetManager.loadModel("Models/Main Chr/Cube.mesh.j3o");
player.setLocalTranslation(1f, 1f, 1f);
//CapsuleCollisionShape capsule = new CapsuleCollisionShape(3f, 4f); - Original
CapsuleCollisionShape capsule = new CapsuleCollisionShape(2f, 10f);
character = new CharacterControl(capsule, 0.05f);
player.scale(3f);
player.addControl(character);
character.setJumpSpeed(20f);
//Maps the Keys to Action/Animation
inputManager.addMapping("CharLeft",new KeyTrigger(KeyInput.KEY_LEFT));
inputManager.addMapping("CharRight",new KeyTrigger(KeyInput.KEY_RIGHT));
inputManager.addMapping("CharForward",new KeyTrigger(KeyInput.KEY_UP));
inputManager.addMapping("CharBackward",new KeyTrigger(KeyInput.KEY_DOWN));
inputManager.addMapping("CharJump",new KeyTrigger(KeyInput.KEY_J));
inputManager.addListener(this, "CharLeft", "CharRight");
inputManager.addListener(this, "CharForward", "CharBackward");
inputManager.addListener(this, "CharJump");
}
@Override
public void update(float tpf) {
//TODO: implement behavior during runtime
flybyCamera.setEnabled(false);
chaseCam = new ChaseCamera(cam, player, inputManager);
chaseCam.setSmoothMotion(true);
chaseCam.setTrailingEnabled(true);
animationControl = player.getControl(AnimControl.class);
animationControl.addListener((AnimEventListener) this);
animationChannel = animationControl.createChannel();
bulletAppState.getPhysicsSpace().add(character);
localRootNode.attachChild(player);
}
private Vector3f walkDirection = new Vector3f(0,0,0); //stop
private float airTime = 0;
public void simpleUpdate(float tpf) {
Vector3f camDir = cam.getDirection().clone();
Vector3f camLeft = cam.getLeft().clone();
camDir.y = 0;
camLeft.y = 0;
camDir.normalizeLocal();
camLeft.normalizeLocal();
walkDirection.set(0,0,0);
if (left) walkDirection.addLocal(camLeft);
if (right) walkDirection.addLocal(camLeft.negate());
if (up) walkDirection.addLocal(camDir);
if (down) walkDirection.addLocal(camDir.negate());
if (!character.onGround()) { // Remember to use !character.isOnGround() if the character is a BetterCharacterControl type.
airTime += tpf;
} else{
airTime =0;
}
if (walkDirection.lengthSquared() ==0) {
if (!"Stand".equals(animationChannel.getAnimationName())) {
animationChannel.setAnim("Stand", 1f);
}
} else {
character.setViewDirection(walkDirection);
if (airTime > .3f) {
if (!"Stand".equals(animationChannel.getAnimationName())) {
animationChannel.setAnim("Stand");
}
} else if (!" Walk".equals(animationChannel.getAnimationName())) {
animationChannel.setAnim(" Walk", 0.1f);
}
}
walkDirection.multLocal(5f).multLocal(tpf); //The use of the first multLocal here is to control the rate of movement multiplier for character walk speed. The second one is to make sure the character walks the same speed no matter what the frame rate is
character.setWalkDirection(walkDirection); // WALKING!!
}
@Override
public void cleanup() {
super.cleanup();
rootNode.detachChild(localRootNode);
guiNode.detachChild(localGuiNode);
//TODO: clean up what you initialized in the initialize method,
//e.g. remove all spatials from rootNode
//this is called on the OpenGL thread after the AppState has been detached
}
public void onAnimCycleDone(AnimControl control,
AnimChannel channel, String animName) {
}
public void onAnimChange(AnimControl control,
AnimChannel channel, String animName) {
}
public void onAction(String binding,boolean value, float tpf) {
if (binding.equals("CharLeft")) {
if (value) left= true;
else left = false;
} else if (binding.equals("CharRight")) {
if (value) right = true;
else right = false;
} else if (binding.equals("CharForward")) {
if (value) up = true;
else up = false;
} else if (binding.equals("CharBackward")) {
if (value) down = true;
else down = false;
}
}
}
**And the main class**
package mygame;
import com.jme3.app.SimpleApplication;
/**
* test
* @author
*/
public class Main extends SimpleApplication {
public boolean isRunning = false;
public GameRunningState gameRunningState;
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
gameRunningState = new GameRunningState();
stateManager.attach(gameRunningState);
}
public void SimpleUpdate(float tpf) {}
}