Book Image

jMonkeyEngine 3.0 : Beginner's Guide

Book Image

jMonkeyEngine 3.0 : Beginner's Guide

Overview of this book

jMonkeyEngine 3.0 is a powerful set of free Java libraries that allows you to unlock your imagination, create 3D games and stunning graphics. Using jMonkeyEngine's library of time-tested methods, this book will allow you to unlock its potential and make the creation of beautiful interactive 3D environments a breeze."jMonkeyEngine 3.0 Beginner's Guide" teaches aspiring game developers how to build modern 3D games with Java. This primer on 3D programming is packed with best practices, tips and tricks and loads of example code. Progressing from elementary concepts to advanced effects, budding game developers will have their first game up and running by the end of this book.From basic concepts and project creation to building a complex 3D Game, you will learn to layout 3D scenes, make them interactive and add various multi-media effects.You will find answers to common questions including best practices and approaches, how game characters can act and interact, how to simulate solid walls and physical forces, how to take it online to play over a network and much more.From Zero to Hero, start your journey to make your game idea a reality.
Table of Contents (20 chapters)
jMonkeyEngine 3.0 Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Setting up jMonkeyEngine in Eclipse


For development with the jMonkeyEngine 3, use the jMonkeyEngine SDK that you can download for free from http://jmonkeyengine.org.

If you want to use your favorite IDE for coding, you can create a code-less jMonkeyEngine project. This makes it possible to use the asset management tools in the SDK, even if you do not use the SDK's code editor. At the same time, you can manage the source code and build a script in Eclipse (or any other IDE).

Since the SDK is built on top of the NetBeans platform, users of NetBeans IDE should feel right at home. In the following tutorial, we show how to download and set up the latest nightly build of the jMonkeyEngine 3 library for use with the Eclipse IDE.

You can find the most current Eclipse setup tips at http://jmonkeyengine.org/wiki/doku.php/jme3:setting_up_jme3_in_eclipse.

Downloading the software

The currently available JAR binaries are the nightly builds.

  1. The nightly build contains the jMonkeyEngine binaries as JAR files. Download the most recent zipped build from http://nightly.jmonkeyengine.com.

  2. Unzip the file and save the directory as jME3_2013-xx-xx in your home directory ($HOME).

  3. Verify that you have at least the following files and directories:

    • lib/ and opt/: The jMonkeyEngine binaries, and libraries used by the jMonkeyEngine (don't remove)

    • jMonkeyEngine.jar: Run this file to see various feature demos (optional)

    • javadoc/: jME3 API documentation (optional but useful)

    • source/: The jMonkeyEngine library's source code (optional but useful)

Creating a new game project

Perform the following steps:

  1. Open the Eclipse IDE.

  2. Choose File | New | Java Project.

  3. Enter the Project Name; for example, HelloJME3.

  4. Click on Finish.

The new Java project appears in the Eclipse Explorer.

Setting up dependencies

Your project depends on the jMonkeyEngine libraries, so it needs to know where they are.

  1. Right-click on the project in the Eclipse Explorer and choose Build Path | Add External Archives.

  2. In the JAR selection dialog, browse to the $HOME/jME3_2013-xx-xx directory.

  3. Select all JARs in the lib directory and click on Open.

All necessary JAR libraries are now on the classpath and should appear in the Referenced Libraries list.

Setting up the assets folder

The jMonkeyEngine SDK creates an assets folder for your projects. In Eclipse, perform the following steps manually:

  1. On the top level of your Eclipse project, create a new directory and name it assets. Save all your game assets into this folder.

  2. In the jMonkeyEngine SDK, choose File | Import Project | External Project Assets from the menu to open the Import External Project Assets wizard.

  3. When the wizard asks for a project folder, browse to your Eclipse project's top-level folder.

  4. When the wizard asks for an assets folder, browse to your Eclipse project's assets folder. Click on Next and then on Finish.

A so-called codeless jMonkeyEngine project gets saved into your Eclipse project. The project also appears in the jMonkeyEngine's Projects window. You use this project to create materials, convert 3D models, and so on.

Writing a simple application

In the Eclipse IDE, you write your code as you are used to.

  1. From the menu, open File | New | New Package. Name the package for example hello.

  2. From the menu, open File | New | Class.

    1. Select package hello.

    2. Name the class; for example, MyGame.

    3. Specify the Superclass as com.jme3.app.SimpleApplication.

    4. Activate the checkbox to create the main() method if this is the main class of your game.

    5. Activate the checkbox for Inheriting Abstract Methods.

  3. Click on Finish.

The new main class based on SimpleApplication opens in the editor. Write your game code, or copy and paste one of the tutorials.

Consult the Eclipse documentation for advice on compiling and deploying your game.