Java examples for Game:JME3
Simple jme3 User Interface
package gui;//from www. j a v a2 s . co m import com.jme3.app.SimpleApplication; import com.jme3.font.BitmapText; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; import com.jme3.renderer.RenderManager; import com.jme3.scene.Geometry; import com.jme3.scene.shape.Box; import com.jme3.ui.Picture; /** * test * * @author normenhansen */ public class SimpleUserInterface extends SimpleApplication { private int distance = 0; private BitmapText distanceText; public static void main(String[] args) { SimpleUserInterface app = new SimpleUserInterface(); app.start(); } @Override public void simpleInitApp() { setDisplayStatView(false); setDisplayFps(false); guiFont = assetManager.loadFont("Interface/Fonts/Cracked.fnt"); distanceText = new BitmapText(guiFont); distanceText.setSize(guiFont.getCharSet().getRenderedSize()); distanceText.move(settings.getWidth() / 2, // X distanceText.getLineHeight(), // Y 0); // Z (depth layer) guiNode.attachChild(distanceText); Picture frame = new Picture("User interface frame"); frame.setImage(assetManager, "Interface/screen.png", false); frame.move(settings.getWidth() / 2 - 265, 0, -2); frame.setWidth(530); frame.setHeight(10); guiNode.attachChild(frame); Picture logo = new Picture("logo"); logo.setImage(assetManager, "Interface/screen.png", true); logo.move(settings.getWidth() / 2 - 47, 2, -1); logo.setWidth(95); logo.setHeight(75); guiNode.attachChild(logo); Box b = new Box(1, 1, 1); Geometry geom = new Geometry("Box", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Blue); geom.setMaterial(mat); rootNode.attachChild(geom); } @Override public void simpleUpdate(float tpf) { distance = (int) Vector3f.ZERO.distance(cam.getLocation()); distanceText.setText("Distance: " + distance); } @Override public void simpleRender(RenderManager rm) { //TODO: add render code } }