Now we start with jMonkeyEngine.
The jMonkeyEngine is a Java 3D game engine.
You can use the Downloads link, which will give you the Downloads available for the major operating systems. These will install the Netbeans IDE and Java SDK, as well as the jMonkeyEngine libraries.
Once the jMonkeyEngine SDK is installed, we can open it and create a new project. For all jMonkeyEngine (JME) applications, we have to select JME3 and BasicGame.
We will then have to give project name, as well as folder it will be saved in.
In a while, in the Projects, you will see the new project. You can expand the folder to see Source Packages, mygame package, and Main.java file. You can open the file by double-clicking Main.java. You can select the Refactor menu and rename it to JMonkey1.
There is default code, which can be modified or you can paste code from a code example. Most importantly, our application class must extend the SimpleApplication class. We start our application with the start() method, which will call simplInitApp(). We must override it, if we want to see visual objects on the screen.
// *** 1. Start (SimpleApplication object) JMonkey1 app = new JMonkey1(); app.start(); // *** 1. End
Here, we create a text object and send it to guiNode. For 3D objects, we have to send them to rootNode.
// *** 2. Start (Text --> guiNode) guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt"); BitmapText helloText = new BitmapText(guiFont, false); helloText.setText("Hello World"); helloText.setLocalTranslation(300, 220, 0); // coordinates guiNode.attachChild(helloText); // *** 2. End
We hide the statistics debugging information.
// *** 3. Start (Clear statistics) setDisplayFps(false); // hide the FPS setDisplayStatView(false); // hide the statistics // *** 3. End
Output:
// JMonkey1.java package mygame; import com.jme3.app.SimpleApplication; import com.jme3.font.BitmapText; public class JMonkey1 extends SimpleApplication { public static void main(String[] args) { // *** 1. Start (SimpleApplication object) JMonkey1 app = new JMonkey1(); app.start(); // *** 1. End } @Override public void simpleInitApp() { // *** 2. Start (Text --> guiNode) guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt"); BitmapText helloText = new BitmapText(guiFont, false); helloText.setText("Hello World"); helloText.setLocalTranslation(300, 220, 0); // coordinates guiNode.attachChild(helloText); // *** 2. End // *** 3. Start (Clear statistics) setDisplayFps(false); // hide the FPS setDisplayStatView(false); // hide the statistics // *** 3. End } }
No comments:
Post a Comment