I’m fairly new to jMonkey… I should mention I’m only a few months into java development as well. As well as it is my first language to dive into… haaaa i know right. Anyways I just wanted to see about getting someone to critique this code and recommend better ways of doing things. This is very basic stuff, but I want to make sure I’m going in the right direction. Thanks in advance
Main
[java]
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;
public class Main extends SimpleApplication {
private Nifty nifty;
public static boolean gs = false;
public static boolean changestate;
GameInterface gameInterface = new GameInterface();
GameState gameState = new GameState();
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
initializeNiftyInterface();
initializeGameInterface();
}
@Override
public void simpleUpdate(float tpf) {
if (changestate){
if (gs){
initializeGameState();
changestate = false;
}
if (!gs){
gameState.setEnabled(false);
changestate = false;
}
}
}
public void initializeNiftyInterface(){
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(getAssetManager(), getInputManager(), getAudioRenderer(), getGuiViewPort());
nifty = niftyDisplay.getNifty();
getGuiViewPort().addProcessor(niftyDisplay);
nifty.fromXml("Interface/GameInterface.xml", "start", gameInterface);
}
public void initializeGameInterface(){
stateManager.attach(gameInterface);
gameInterface.initialize(stateManager, this);
gameInterface.setEnabled(true);
flyCam.setDragToRotate(true);
flyCam.setEnabled(false);
}
public void initializeGameState(){
stateManager.attach(gameState);
gameState.initialize(stateManager, this);
gameState.setEnabled(true);
flyCam.setDragToRotate(false);
flyCam.setEnabled(true);
}
}
[/java]
This is a new appstate for testing in switching from the “menu” to the actual game.
[java]
package mygame;
import com.jme3.app.Application;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
public class GameState extends AbstractAppState {
private Main app;
private Node rootNode;
private Geometry boxGeom;
@Override
public void initialize(AppStateManager stateManager, Application app) {
this.app = (Main) app;
this.rootNode = this.app.getRootNode();
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
boxGeom = new Geometry("Box", b);
Material mat = new Material(this.app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Red);
boxGeom.setMaterial(mat);
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (enabled) {
rootNode.attachChild(boxGeom);
} else {
rootNode.detachChild(boxGeom);
}
}
@Override
public void update(float tpf) {
super.update(tpf);
}
}
[/java]
Here is the games interface
[java]
package mygame;
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.scene.Node;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;
public class GameInterface extends AbstractAppState implements ScreenController {
private SimpleApplication app;
private Nifty nifty;
private Screen screen;
private Node rootNode;
public void bind(Nifty nifty, Screen screen) {
this.nifty = nifty;
this.screen = screen;
}
public void onStartScreen() {
}
public void startGame(String nextScreen){
nifty.gotoScreen(nextScreen);
Main.gs = true;
Main.changestate = true;
}
public void onEndScreen() {
}
public void quitGame() {
app.stop();
}
@Override
public void initialize(AppStateManager stateManager, Application app) {
this.app = (Main) app;
this.rootNode = this.app.getRootNode();
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (enabled) {
} else {
}
}
@Override
public void update(float tpf) {
super.update(tpf);
}
}
[/java]
And here is the interface xml for switching from “start” to “hud”
[xml]
[/xml]
Like i said all of this is very basic stuff, I just don’t want to get off to a wrong start. And if I already am please let me know, I am just wanting to learn! Thanks again! And a big thanks to the jMonkey team and everything that you do