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.
Perform the following set of steps to load a level:
We start by defining a new message class:
LoadLevelMessage
. It extendsGameMessage
since it might be useful to know thegameId
. Apart from that, it has one fieldlevelName
.We'll add the same field to our
Game
class so that it can keep track of which level it's running.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...