Browse Source

Note that client cameras should be created into a local node in networked applications.

Lasse Öörni 11 years ago
parent
commit
6d5c73a15f

+ 4 - 0
Bin/Data/LuaScripts/17_SceneReplication.lua

@@ -85,6 +85,10 @@ function CreateScene()
     end
 
     -- Create the camera. Limit far clip distance to match the fog
+    -- The camera needs to be created into a local node so that each client can retain its own camera, that is unaffected by
+    -- network messages. Furthermore, because the client removes all replicated scene nodes when connecting to a server scene,
+    -- the screen would become blank if the camera node was replicated (as only the locally created camera is assigned to a
+    -- viewport in SetupViewports() below)
     cameraNode = scene_:CreateChild("Camera", LOCAL)
     local camera = cameraNode:CreateComponent("Camera")
     camera.farClip = 300.0

+ 4 - 0
Bin/Data/Scripts/17_SceneReplication.as

@@ -96,6 +96,10 @@ void CreateScene()
     }
 
     // Create the camera. Limit far clip distance to match the fog
+    // The camera needs to be created into a local node so that each client can retain its own camera, that is unaffected by
+    // network messages. Furthermore, because the client removes all replicated scene nodes when connecting to a server scene,
+    // the screen would become blank if the camera node was replicated (as only the locally created camera is assigned to a
+    // viewport in SetupViewports() below)
     cameraNode = scene_.CreateChild("Camera", LOCAL);
     Camera@ camera = cameraNode.CreateComponent("Camera");
     camera.farClip = 300.0f;

+ 2 - 0
Docs/Reference.dox

@@ -1892,6 +1892,8 @@ The server can be made to transmit needed resource \ref PackageFile "packages" t
 
 There are some things to watch out for:
 
+- When a client is assigned to a scene, the client will first remove all existing replicated scene nodes from the scene, to prepare for receiving objects from the server. This means that for example a client's camera should be created into a local node, otherwise it will be removed when connecting.
+
 - After connecting to a server, the client should not create, update or remove non-local nodes or components on its own. However, to create client-side special effects and such, the client can freely manipulate local nodes.
 
 - A node's \ref Node::GetVars "user variables" VariantMap will be automatically replicated on a per-variable basis. This can be useful in transmitting data shared by several components, for example the player's score or health.

+ 4 - 0
Source/Samples/17_SceneReplication/SceneReplication.cpp

@@ -143,6 +143,10 @@ void SceneReplication::CreateScene()
     }
     
     // Create the camera. Limit far clip distance to match the fog
+    // The camera needs to be created into a local node so that each client can retain its own camera, that is unaffected by
+    // network messages. Furthermore, because the client removes all replicated scene nodes when connecting to a server scene,
+    // the screen would become blank if the camera node was replicated (as only the locally created camera is assigned to a
+    // viewport in SetupViewports() below)
     cameraNode_ = scene_->CreateChild("Camera", LOCAL);
     Camera* camera = cameraNode_->CreateComponent<Camera>();
     camera->SetFarClip(300.0f);