Game Development Reference
In-Depth Information
6. Next, we create playerGeometry to be used for all the players in this ex-
ample, as follows:
Material playerMaterial = new
Material(assetManager, "Common/MatDefs/Misc/
Unshaded.j3md");
playerGeometry = new Geometry("Player", new
Box(1f,1f,1f));
playerGeometry.setMaterial(playerMaterial);
7. We also turn off the application's flyByCamera instance and create a new
game object, which we will populate when we receive information from the serv-
er, as follows:
getFlyByCamera().setEnabled(false);
game = new Game();
8. Lastly, we create a new ClientMessageListener object and add it to the
client, as shown in the following code snippet:
ClientMessageHandler messageHandler = new
ClientMessageHandler(this, game);
client.addMessageListener(messageHandler);
9. In the createPlayer method, we create a new ClientPlayerControl
instance and also a Node instance, which we attach to the scene graph, as fol-
lows:
ClientPlayerControl player = new
ClientPlayerControl();
player.setId(id);
final Node playerNode = new Node("Player Node");
playerNode.attachChild(assetManager.loadModel("Models/
Jaime/Jaime.j3o"));//
playerNode.addControl(player);
10. Since we don't know when this method will be called, we make sure that we at-
tach the spatial in a thread-safe way. This can be implemented as follows:
Search WWH ::




Custom Search