Hi Guys. I’ll get straight to the point, but first let me show my AbstractAppState Class code:
[java]package views;
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.audio.AudioRenderer;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.VehicleControl;
import com.jme3.input.FlyByCamera;
import com.jme3.input.InputManager;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.renderer.ViewPort;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.NiftyEventSubscriber;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.elements.events.NiftyMousePrimaryClickedEvent;
import de.lessvoid.nifty.elements.render.TextRenderer;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;
import graphics.Train;
public class HudScreen extends AbstractAppState implements ScreenController
{
private SimpleApplication app;
private AssetManager assetManager;
private InputManager inputManager;
private AppStateManager stateManager;
private ViewPort guiViewPort;
private AudioRenderer audioRenderer;
private FlyByCamera flyByCamera;
private BulletAppState bullet;
private NiftyJmeDisplay niftyDisplay;
private Nifty nifty;
private Screen currentScreen;
private TextRenderer trainCarsNumberDisplay;
private TextRenderer trainAccelerationForceDisplay;
private Train trainState;
// User Settings for the simulation - they will be
// displayed in the right hand side panel during simulation
private int trainCarsNumberP;
private int trainAcceleration;
private int trainMaxSpeed;
boolean isPress = false;
@Override
public void initialize(AppStateManager stateManager, Application app)
{
super.initialize(stateManager, app);
this.app = (SimpleApplication) app;
this.assetManager = this.app.getAssetManager();
this.inputManager = this.app.getInputManager();
this.guiViewPort = this.app.getGuiViewPort();
this.audioRenderer = this.app.getAudioRenderer();
this.flyByCamera = this.app.getFlyByCamera();
this.stateManager = this.app.getStateManager();
this.bullet = this.stateManager.getState(BulletAppState.class);
this.trainState = this.stateManager.getState(Train.class);
niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, this.audioRenderer, this.guiViewPort);
nifty = niftyDisplay.getNifty();
setGUI();
setGUIDebugMode(false);
setGUIControllers();
setGUICameras();
}
private void setGUI() {
nifty.addXml("Interface/hudScreenUI.xml");
nifty.gotoScreen("hudScreen");
}
private void setGUIDebugMode(boolean isOn) {
nifty.setDebugOptionPanelColors(isOn);
}
// Every gui that require access to state manager has to be registered
private void setGUIControllers() {
stateManager.attach(this);
}
private void setGUICameras() {
this.guiViewPort.addProcessor(niftyDisplay);
this.flyByCamera.setDragToRotate(true);
this.flyByCamera.setEnabled(false);
}
// Screen listeners
/*@NiftyEventSubscriber(id="startSimulation")
public void onStartSimulationClick(String id, NiftyMousePrimaryClickedEvent event) {
//System.out.println("Train Cars Array Size:" + this.trainCarsNumberP);
if(!isPress){
isPress = true;
} else {
isPress = false;
}
}*/
public void startGame() {
if(!isPress){
isPress = true;
} else {
isPress = false;
}
System.out.println("Set Value " + isPress);
}
public void bind(Nifty nifty, Screen screen) {
this.nifty = nifty;
this.currentScreen = screen;
}
public void onStartScreen() {
Element trainCarsDisplay = currentScreen.findElementByName("trainCarsDisplay");
trainCarsNumberDisplay = trainCarsDisplay.getRenderer(TextRenderer.class);
trainCarsNumberDisplay.setText("f" + trainCarsNumberP);
}
public void onEndScreen() {
}
@Override
public void update(float tpf) {
super.update(tpf);
if(isPress)
{
trainCarsNumberP = stateManager.getState(Train.class).getTrainCarsNumber();
System.out.println("Set Value " + trainCarsNumberP);
}
VehicleControl firstCar = stateManager.getState(Train.class).getTrain().get(0).getTrainCarVehicleControl();
firstCar.accelerate(-20);
//System.out.println("Set Value " + isPress);
// System.out.println("Train Cars Array Size:" + this.trainState.getTrainCarsNumber());
//startGame();
//System.out.println("Train Cars Array Size:" + this.app.getStateManager().getState(Train.class).getTrainCarsNumber());
}
[/java]
Now what I’m trying to do is to change the variable isPress to true or false etc. to manipulate some block of code in if…else conditional statement inside update() loop. I want to do this on a click of a button - in nifty xml I have:
But it seems that update loop doesn’t see the change. I don’t even know if I’m doing this correctly. Can someone point me in the right direction? I’m kind of a noob. Basically I want to control a train in a similar way to this guy:
In his code he is using the conditional statements to control the movement. How can I do that?