if someone could bear with me on this, I’d appreciate it.
I have a class called hud.java,
[java]
import com.jme3.app.SimpleApplication;
import com.jme3.font.BitmapText;
public class hud extends SimpleApplication {
public hud() {
}
public void initHUD(main app) {
app.guiNode.detachAllChildren();
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
BitmapText ch = new BitmapText(guiFont, false);
ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
ch.setText("+"); // crosshairs
ch.setLocalTranslation( // center
settings.getWidth() / 2 - guiFont.getCharSet().getRenderedSize() / 3 * 2,
settings.getHeight() / 2 + ch.getLineHeight() / 2, 0);
guiNode.attachChild(ch);
}
@Override
public void simpleInitApp() {
}
}
[/java]
And then my main.java:
[java]
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
import com.jme3.math.FastMath;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.texture.Texture;
class main extends SimpleApplication {
private static main app;
private BulletAppState bulletAppState;
private RigidBodyControl floorPhy;
public static void main(String[] args) {
app = new main();
app.start();
}
@Override
public void simpleInitApp() {
//Initialize physics space
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
// Create the floor
Box floorBox = new Box(Vector3f.ZERO, 30, 0, 30);
floorBox.scaleTextureCoordinates(new Vector2f(22,22));
Geometry floorGeom = new Geometry("Floor", floorBox);
Material floorMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture floorTex = assetManager.loadTexture("floor.png");
floorTex.setWrap(Texture.WrapMode.Repeat);
floorMat.setTexture("ColorMap", floorTex);
floorGeom.setMaterial(floorMat);
rootNode.attachChild(floorGeom);
floorPhy = new RigidBodyControl(0.0f);
floorGeom.addControl(floorPhy);
bulletAppState.getPhysicsSpace().add(floorPhy);
// Create the ceiling
Box ceilBox = new Box(Vector3f.ZERO, 10, 0, 10);
ceilBox.scaleTextureCoordinates(new Vector2f(15,15));
Geometry ceilGeom = new Geometry("Roof", ceilBox);
Material ceilMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture ceilTex = assetManager.loadTexture("ceiling.png");
ceilTex.setWrap(Texture.WrapMode.Repeat);
ceilMat.setTexture("ColorMap", ceilTex);
ceilGeom.setMaterial(ceilMat);
ceilGeom.setLocalTranslation(new Vector3f(0,5,0));
rootNode.attachChild(ceilGeom);
// Create the (4) walls
Box wallBox = new Box(Vector3f.ZERO, 2, 2.5f, 0);
Geometry[] wall = new Geometry[16];
Material wallMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture wallTex = assetManager.loadTexture("wall.png");
wallTex.setWrap(Texture.WrapMode.Repeat);
wallMat.setTexture("ColorMap", wallTex);
wall[0] = new Geometry("Wall 1", wallBox);
wall[0].setMaterial(wallMat);
wall[0].setLocalTranslation(0,2.5f,10);
rootNode.attachChild(wall[0]);
wall[1] = new Geometry("Wall 2", wallBox);
wall[1].setMaterial(wall[0].getMaterial());
wall[1].setLocalTranslation(8,2.5f,10);
rootNode.attachChild(wall[1]);
wall[2] = new Geometry("Wall 3", wallBox);
wall[2].setMaterial(wall[0].getMaterial());
wall[2].rotate(0f, FastMath.DEG_TO_RAD * 90, 0f);
wall[2].setLocalTranslation(10,2.5f,8);
rootNode.attachChild(wall[2]);
wall[3] = new Geometry("Wall 4", wallBox);
wall[3].setMaterial(wall[0].getMaterial());
wall[3].setLocalRotation(wall[2].getLocalRotation());
wall[3].setLocalTranslation(10, 2.5f, 0);
rootNode.attachChild(wall[3]);
wall[4] = new Geometry("Wall 5", wallBox);
wall[4].setMaterial(wall[0].getMaterial());
wall[4].setLocalRotation(wall[3].getLocalRotation());
wall[4].setLocalTranslation(10, 2.5f, -8);
rootNode.attachChild(wall[4]);
wall[5] = new Geometry("Wall 6", wallBox);
wall[5].setMaterial(wall[0].getMaterial());
wall[5].setLocalTranslation(0, 2.5f, -10);
rootNode.attachChild(wall[5]);
wall[6] = new Geometry("Wall 7", wallBox);
wall[6].setMaterial(wall[0].getMaterial());
wall[6].setLocalTranslation(8, 2.5f, -10);
rootNode.attachChild(wall[6]);
wall[7] = new Geometry("Wall 8", wallBox);
wall[7].setMaterial(wall[0].getMaterial());
wall[7].setLocalTranslation(-8, 2.5f, 10);
rootNode.attachChild(wall[7]);
wall[8] = new Geometry("Wall 8", wallBox);
wall[8].setMaterial(wall[0].getMaterial());
wall[8].setLocalTranslation(-8, 2.5f, -10);
rootNode.attachChild(wall[8]);
//Big back wall
Box bigWallBox = new Box(Vector3f.ZERO, 10, 2.5f, 0);
bigWallBox.scaleTextureCoordinates(new Vector2f(5,1));
wall[9] = new Geometry("Wall 9", bigWallBox);
wall[9].setMaterial(wallMat);
wall[9].setLocalRotation(wall[2].getLocalRotation());
wall[9].setLocalTranslation(-10, 2.5f, 0);
rootNode.attachChild(wall[9]);
flyCam.setMoveSpeed(75);
guiNode.detachAllChildren();
hud myhud = new hud();
myhud.initHUD();
}
}
[/java]
I tried to pass in my app in main.java as a parameter for initHud() and it didnt work. I also tried to pass it in the constructor of hud.java, but I wasn’t sure what to do after passing it into the constructor. Thanks again.