Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
jMonkeyEngine 3.0 : Beginner's Guide
jMonkeyEngine 3.0 : Beginner's Guide

jMonkeyEngine 3.0 : Beginner's Guide: Whether you want to design 3D games with Java for love or for money, this is the primer you need to start using the free libraries of jMonkeyEngine 3.0. All hands on, all fun – it makes light work of learning.

€32.99 €22.99
Book Jun 2013 352 pages 1st Edition
eBook
€32.99 €22.99
Print
€41.99
Subscription
€14.99 Monthly
eBook
€32.99 €22.99
Print
€41.99
Subscription
€14.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Jun 25, 2013
Length 352 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781849516464
Category :
Table of content icon View table of contents Preview book icon Preview Book

jMonkeyEngine 3.0 : Beginner's Guide

Chapter 1. Installing jMonkeyEngine

When a group of heroes set out on a quest, they grab their armor and weapons—when you set out on a game development adventure, you grab the jMonkeyEngine SDK.

The jMonkeyEngine Software Development Kit (SDK) contains everything that you need to get started quickly: the jMonkeyEngine libraries, Javadoc, sample code, and lots of nifty game development utilities. This bundle also includes all necessary native libraries, such as LightWeight Java Game Library (LWJGL). This means there is no second installation step, neither for the development team, nor for users of the games that we create.

In this chapter you will learn:

  • What the hardware and software requirements are

  • How to install the jMonkeyEngine SDK

  • How the tools in the jMonkeyEngine SDK make a developer's life easier

  • How to create and distribute jMonkeyEngine games

Installation requirements for game developers


At the time of printing, the jMonkeyEngine SDK needs 40 MB of memory, plus enough memory to load the particular game's assets. Your computer should have a minimum of 1 GHz CPU, and your graphic card must support OpenGL 2.0, or better. Suitable graphic cards include ATI Radeon 9500, NVIDIA GeForce 5 FX, Intel GMA 4500, and all newer ones.

You can use the jMonkeyEngine SDK on all operating systems that support the Java Development Kit 6 (JDK 6) or better. Currently this includes Windows XP/Windows Vista/Windows 7 or better, Mac OS X 10.5 or better, and Linux kernel 2.6 or better.

Enter the following command in your terminal to check whether you have the required Java Development Kit (JDK) installed:

javac -version

If this command returns javac 1.6.x or better, then your Java installation is set to go. If you still need to install the JDK, click on the Download JDK button at http://www.oracle.com/technetwork/java/javase/downloads/index.html and follow the installation instructions there.

Time for action – installing the jMonkeyEngine SDK


The jMonkey team devised the jMonkeyEngine SDK to make the installation process as smooth as possible:

  1. Go to http://jmonkeyengine.org/downloads/.

  2. Download the jME3 SDK for your operating system and unzip it, if necessary.

  3. Double-click on the installer and complete the installation wizard.

It's time for your first test run:

  1. Find the jMonkeyEngine SDK icon in your Applications folder or Start menu and double-click on it to run the SDK.

  2. When the jMonkeyEngine SDK opens for the first time, a dialog box asks you to specify a folder for storing your projects. Browse to your home directory, click on the Create new folder button, and name the folder jMonkeyProjects.

  3. With your new folder still selected, click on Set Project Folder to close the dialog box.

When the SDK opens, you will see the following application screen:

The Projects window, on the top left-hand side, is where you will browse Java files and manage Java packages, among other things. The SDK also contains an editor window for Java files, not visible here, that we will look at in a minute. At the bottom right-hand side of the screen, you see the Output - Application window; this is where build messages, runtime exceptions, warnings, and println() appear.

In the center, you see the OpenGL Window. We will use it later to preview the 3D scenes that we created using the Properties, SceneExplorer, and SceneComposer windows, not visible here.

The other two windows you can ignore for now. Later you may use the FilterExplorer window to configure special effects, and the AssetPackBrowser window to bundle up collections of 3D models.

Congrats, your tools are ready, and you have accomplished your first mission. Let's take a closer look at the jMonkeyEngine SDK.

jMonkeyEngine SDK at your service


The jMonkeyEngine SDK is your graphical user interface for the jMonkeyEngine library. The jMonkey team devised this integrated development environment (IDE) especially for 3D game development with Java. The jMonkeyEngine SDK assists you from start to end, whether you write code, integrate game assets, lay out scenes, or deploy the finished application.

Creating your Java game projects with jMonkeyEngine SDK has the added value that they are already preconfigured:

  • The jMonkeyEngine JAR files and native libraries are on the classpath

  • Javadoc popups and code completion for jMonkeyEngine methods are set up in the source editor

  • The provided Ant build script is ready to build, run, and deploy your application

At the same time, there is nothing proprietary about the projects that the SDK creates: you are looking at standard Java SE projects. The SDK's clean, build, and run actions are automated using standard Ant build scripts. The Apache Ant build tool is already included when you install the SDK.

Tip

Did you know?

jMonkeyEngine SDK is built on top of the NetBeans Platform. This means that you can install all kinds of NetBeans IDE plugins. The NetBeans plugins prepackaged in the jMonkeyEngine SDK include version control tools and a Java debugger. Open the jMonkeyEngine SDK and choose Tools | Plugins from the menu, then click on Available Plugins to browse and install other cool add-ons for free, such as a Java profiler.

Can I work in other Java IDEs?


Although this book will repeatedly tell you how awesome the jMonkeyEngine SDK is, you are not forced to use it for coding. The jMonkeyEngine library is open source software: If you download the latest binary bundle from http://www.jmonkeyengine.com/nightly/, you can manually add the JAR files from the lib directory to your CLASSPATH, just like any other Java library. You can link these libraries in your favorite Java IDE, or do your Java development in a text editor on the command line if that's how you roll.

For now, let's continue using the SDK because it will get you started more swiftly. This book strives to keep code samples IDE-independent. If a shortcut or workflow only applies to the jMonkeyEngine SDK, it will be clearly pointed out as such.

Nonetheless you should give the jMonkeyEngine SDK a try. It contains many plugins that you will not find in generic IDEs: an asset pack manager and file converters for 3D models, a scene viewer and scene composer, a terrain editor, a procedural texture generator, a code snippet palette, and much more. Try it! If you are not convinced by the end of this book, you will find setup instructions for other IDEs in the appendix. Deal?

Time for action – running a demo


In order to test whether everything was installed correctly, let's run a few demos. A set of demos comes bundled with the jMonkeyEngine SDK as one of the project templates.

  1. Choose File | New Project from the menu to open the New Project wizard.

  2. Select JME3 Tests from the jME3 category.

  3. Accept the defaults and complete the wizard.

The SDK unpacks the bundled demos and makes copies of the demo sources. The new JME3 Tests project appears in the Projects window.

To run a demo:

  1. Right-click on JME3 Tests and click on Build and Run. Wait for the TestChooser window to open.

  2. For example, select the TestWalkingChar demo and click on OK.

    Tip

    Type walking into the filter box to find it more quickly.

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

  4. When the demo opens, use the WASD keys and drag the mouse to navigate the simple scene. Press the Space bar to shoot fireballs.

  5. When you have seen enough of this demo, the press Esc key. Either select another demo, or click on Cancel to exit.

Now that you know how to use the TestChooser, run some demos to see what is possible with jMonkeyEngine.

What just happened?

It's good to know that, during the development process, you can always return to the JME3 Tests demos for inspiration. Browse the demo's Source Package if you are looking for code samples that showcase particular features. Feel free to modify your copy of the code samples and experiment. In the unlikely case that you break the project, you can always recreate the JME3 Tests template from the New Project menu.

Restoring the demos is as easy as creating a fresh game project, which is what we will do next.

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.

Assets and the art pipeline


Every 3D game requires some multimedia assets, whether it's 3D models, image files, sound clips, video clips, or music. This book focuses on the development aspect—how to tie assets and code together and deploy the game. Being able to write source code only takes you halfway there: to develop games, you also need to go through the art pipeline.

By art pipeline we mean the creative process of creating 3D models, composing background music, and so on. The art pipeline runs in stages parallel to your coding milestones:

  1. Lay out concept art, either digital or on paper, to get an idea of what you need; you do this in parallel to planning your Java object model.

  2. Insert mock-up art in alpha builds: these sample files don't look and sound like the real thing yet. They are merely placeholders in the right size and format that help you debug your loading code.

  3. Insert drafts in beta builds that are close to the final look and feel that you want; this helps you beta test and iron out the kinks.

  4. Include the final artwork in the release builds. Typically, assets are converted to data formats that are optimized for the target platform.

Including sounds and images in your game means that you either need access to a multimedia library, or you need to create your assets using external tools.

The jMonkeyEngine SDK does not include any multimedia editors. This is because a game engine should not prescribe the artist's choice of design software. You are free to create assets in any third-party tools that you fancy and have access to. Just make certain that you can export the artwork in formats that jMonkeyEngine supports.

The following external file types are supported by jMonkeyEngine:

Supported File Type

Usage

.mesh.xml, .material,

.skeleton.xml, .scene

Ogre Mesh XML (3D models)

Ogre DotScene (3D scenes)

.obj, .mtl

Wavefront objects (3D models)

.blend

Blender files (3D models)

.jpg, .png, .tga, .gif,

.dds, .hdr, .pfm

Images and textures

.fnt

Bitmap fonts

.wav, .ogg

Wave and OGG Vorbis audio

If you have not chosen your multimedia tools yet, the following are some suggestions of popular editors that support the formats mentioned earlier:

All of these are examples of software that is available for Windows, Mac OS, and Linux; all three are open source, and you can download and use them for free.

There are many more free and paid design tools available if you do a search. Whichever software you choose to create your assets, consult the respective manuals for details on how to use them. 3D modeling in particular is not a trivial task, but it's definitely worth learning.

Now that you have the design and development tools installed, you have everything you need to create your game.

But what do your users install to play your game?

Time for action – distributing a game


During the development phase, you typically build and run your game right from the jMonkeyEngine SDK. Your users, however, neither have nor want the SDK. They expect to run the game by, for instance, executing a desktop application that runs on their Java Virtual Machine.

Switch to the Files window, and look into the dist folder. Every time you Build this project, the SDK generates an executable JAR file here. When you right-click on the project and choose Clean, the dist folder is deleted—so remember never to move any unique files there.

Let's go through the basic deployment process together:

  1. Right-click on the BasicGame project in SDK, and open the project's Properties window.

  2. Go to the Application | Desktop pane and select the checkboxes for your target operating systems, for example Windows, Mac, and Linux. Click on OK.

  3. Right-click on the BasicGame project, and Clean and Build it.

Look into the Output window to follow the build process.

What just happened?

When the build is finished, switch to your operating system's file explorer:

  1. Browse to the jMonkeyProjects/BasicGame/dist/ folder in your user home.

  2. Unzip and run the BasicGame executable for your operating system.

  3. The application window opens and displays the blue cube demo. Press the Esc key to quit.

This exercise shows you that the SDK generates distributable builds of your BasicGame project that runs fine on your desktop, outside the jMonkeyEngine SDK.

Impressive—you have just built a basic 3D application that runs on the three most widely used operating systems. Notice how you didn't have to configure any CLASSPATH or library paths.

Can I sell my jMonkeyEngine game?


Yes, the jMonkeyEngine SDK is a free open source software released under the BSD license. To answer the most common questions right away:

  • You do not pay any fees to use the jMonkeyEngine libraries or SDK

  • You can use the jMonkeyEngine for hobby, educational, or commercial purposes

  • You can include the jMonkeyEngine libraries in a Java application that you sell or give away for free

  • You can offer your application that includes the jMonkeyEngine libraries as download, serve it over the network, or distribute it on digital media

  • Using the jMonkeyEngine does not require you to open source your own code (but you can)

All that is required from you is that you adhere to the BSD license, and keep the license together with the jMonkeyEngine libraries included in your distribution. Simply copy the license from the jMonkeyHomepage. Don't worry, it's nice and short and can be found at http://jMonkeyEngine.org/wiki/doku.php/bsd_license.

Summary


In this chapter you learned how to install the jMonkeyEngine SDK and run sample applications. You saw that it is easy to get started with game development using the jMonkeyEngine SDK, and how easy it is to distribute a game using the jMonkeyEngine SDK.

Come on over to the next chapter, where we write some actual code!

Left arrow icon Right arrow icon

Key benefits

  • Create 3D games that run on Android devices, Windows, Mac OS, Linux desktop PCs and in web browsers ‚Äì for commercial, hobbyists, or educational purposes.
  • Follow end-to-end examples that teach essential concepts and processes of game development, from the basic layout of a scene to interactive game characters.
  • Make your artwork come alive and publish your game to multiple platforms, all from one unified development environment.

Description

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.

What you will learn

Create your own worlds and populate them with mobile characters, cities, physical objects, natural landscapes or beautiful under-water scenes. Add cool sounds and awesome visual effects to draw the player into your interactive world. Design textured materials and use light and shadow to bring out your game s unique atmosphere. Make players shoot, select items, walk or look round by registering and handling user input. Keep track of the game state and determine how each character makes decisions and responds to attacks. Make the most of the integrated physics engine and create fast-paced car races, bowling, sports, pool and billiards games. Understand client-server messaging and create multi-player online games that communicate over a network.

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Jun 25, 2013
Length 352 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781849516464
Category :

Table of Contents

20 Chapters
jMonkeyEngine 3.0 Beginner's Guide Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Author Chevron down icon Chevron up icon
About the Reviewers Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
Installing jMonkeyEngine Chevron down icon Chevron up icon
Creating Your First 3D Scene Chevron down icon Chevron up icon
Interacting with the User Chevron down icon Chevron up icon
Adding Character to Your Game Chevron down icon Chevron up icon
Creating Materials Chevron down icon Chevron up icon
Having Fun with Physics Chevron down icon Chevron up icon
Adding Spark to Your Game Chevron down icon Chevron up icon
Creating Landscapes Chevron down icon Chevron up icon
Making Yourself Heard Chevron down icon Chevron up icon
Showing Your Game to the World Chevron down icon Chevron up icon
What's Next? Chevron down icon Chevron up icon
Additional Resources for Fellow jMonkeys Chevron down icon Chevron up icon
Pop Quiz Answers Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.