Book Image

JMonkeyEngine 3.0 Cookbook

By : Rickard Eden
Book Image

JMonkeyEngine 3.0 Cookbook

By: Rickard Eden

Overview of this book

Table of Contents (17 chapters)
jMonkeyEngine 3.0 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Loading a level


No matter if it's an FPS, RTS, or driving game we're making, we'll want to be able to load different kinds of environments for the players to roam around in. How can we do that easily?

In this recipe, we'll add functionalities to the networked FPS game we outlined previously in this chapter. The principle will work for any kind of already networked game, although it might differ depending on how the game implements the level. Here, we'll assume it uses jMonkeyEngine scenes or .j3o scenes.

How to do it...

Perform the following set of steps to load a level:

  1. We start by defining a new message class: LoadLevelMessage. It extends GameMessage since it might be useful to know the gameId. Apart from that, it has one field levelName.

  2. We'll add the same field to our Game class so that it can keep track of which level it's running.

  3. Next, let's create a levelNode field on our server, which we can load our level into, as follows:

    private Node loadLevel(String levelName){
      return (Node) assetManager...