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

Time for action – creating a project


The jMonkeyEngine SDK provides you with a preconfigured project template that gets you started at lightning speed.

This is how you create a new project:

  1. Choose File | New Project from the menu

  2. Select BasicGame from the jME3 category.

  3. You can rename the project here, but for now, accept the defaults and complete the wizard.

A new Java project named BasicGame appears in the Projects window, next to the JME3 Tests project.

The BasicGame project contains a simple Main.java template. Let's try to run this Java application:

  1. Open the BasicGame project's Source Packages, and double-click on the mygame/Main.java file to open it. You see that the JDK contains a full-featured editor for Java files.

  2. Right-click on the BasicGame project and click on Build and Run.

  3. Accept the default display settings and click on OK.

  4. The application window opens and shows a blue 3D cube on a black background. If this works, you know that your project is set up correctly.

  5. Press the Esc key to quit the BasicGame project's window.

As you can see, it's easy to create and run fully preconfigured game projects in the jMonkeyEngine SDK.

What just happened?

Let's open the BasicGame folder in the Projects window and look at the project structure that the SDK has just created for you.

You can see that the Projects window gives you access to three important areas: Project Assets, Source Packages, and Libraries, as well as the build script.

The Projects window shows the logical structure of a jMonkeyEngine project. This view only displays files that you need during development, and it filters out build folders and configuration files. For comparison, have a look at the project's physical structure, which lets you browse the actual files on your hard drive; choose Window | Files from the menu to open the Files window. Click the triangles to open the subsections and compare the two views, as shown in the previous screenshot.

Browse the Libraries section in the Projects window. You can see that it lists all the JAR files that are preconfigured on this project's CLASSPATH. Compare this to the physical dist/lib directory in the Files window.

If you know about Ant build scripts, you may want to open the Important Files node in the Projects window and browse the preconfigured Ant targets. Compare this to the physical build file, build.xml in the Files window.

You will see that a jMonkeyEngine-based application is a standard Java project made up of the following files and folders:

Project folder

Usage

JMonkeyProjects/BasicGame/assets

You store multimedia assets here

jMonkeyProjects/BasicGame/build/

The SDK generates build classes here

jMonkeyProjects/BasicGame/build.xml

You customize the Ant build script here

jMonkeyProjects/BasicGame/dist/

The SDK generates executables here

jMonkeyProjects/BasicGame/nbproject/

The SDK stores the default build script and metadata here

jMonkeyProjects/BasicGame/src/

You store source code here

jMonkeyProjects/BasicGame/test/

You store JUnit test classes here (optional)

Certain files and folders are automatically created and maintained by the jMonkeyEngine SDK such as build, dist, and nbproject. The SDK recreates these files and folders when you build the application, so do not edit them.

The other folders, highlighted in yellow, contain your sources and assets. Using the test folder is optional; for now, just ignore it. As in any Java project, you have full control over the project's build.xml file, and your two main folders, assets and src.

Switch back to the Projects window. You see that the Project Assets folder corresponds to jMonkeyProjects/BasicGame/assets/, and the Source Packages folder corresponds to jMonkeyProjects/BasicGame/src/. You are free to set up subfolders and packages inside these two folders, as your project requires.

Your Java classes obviously go into Source Packages, but what does the Project Assets folder contain? Open the Project Assets folder and look inside: you will see subfolders for Sounds, Textures, and Models. This folder is where you store your multimedia content.