官术网_书友最值得收藏!

Time for action – starting the application

In the main() method of the class, you need to create a new instance of the application and call its start() method. In this case, the main class is called Main, but you can also name it MyGame or whatever you like:

public static void main(String[] args) {
  Main app = new Main();
  app.start();
}

When you run this code, the application window opens and the jMonkeyEngine starts rendering the scene.

What just happened?

Every jMonkeyEngine application provides the following methods for starting and stopping the game:

Tip

When a user presses the Alt + Tab shortcut or clicks outside the game window, the running application loses focus. You can set app.setPauseOnLostFocus as true, to specify that your game should pause whenever the window loses focus. For real-time or online games, set app.setPauseOnLostFocus as false instead, to keep the game running.

Let's sum up what we just learned. When you write a jMonkeyEngine game, you have to:

  • Extend com.jme3.app.SimpleApplication
  • Implement abstract methods, such as simpleInitApp(), simpleUpdate(float tpf), and simpleRender(RenderManager rm) (described later in the chapter)
  • Call app.start() on your instance of SimpleApplication

The jMonkeyEngine runs the application even if you leave the three method bodies empty. If you run a SimpleApplication class without initializing any scene, the screen shows up empty.

主站蜘蛛池模板: 武安市| 襄垣县| 海宁市| 阳江市| 武宣县| 万源市| 常德市| 三门县| 南澳县| 扶沟县| 南漳县| 永年县| 永德县| 修文县| 十堰市| 西乌| 县级市| 公主岭市| 东台市| 泾阳县| 秦皇岛市| 绥德县| 宁城县| 新宁县| 达尔| 龙江县| 自治县| 大关县| 咸阳市| 卓尼县| 湘潭县| 华阴市| 玉田县| 龙南县| 江永县| 资中县| 洛隆县| 永清县| 车致| 文水县| 河曲县|