Prechádzať zdrojové kódy

Fixed physics debug example and added description regarding collection proxy and slowing time for debugging. (#136)

Pawel 1 mesiac pred
rodič
commit
77cae1d047

BIN
debug/physics/collectionproxy.png


+ 14 - 2
debug/physics/example.md

@@ -3,9 +3,21 @@ tags: debug
 title: Physics debug
 title: Physics debug
 brief: This example allows you to toggle physics debug visualization as well as changing the time step so the simulation runs at one tenth of the speed.
 brief: This example allows you to toggle physics debug visualization as well as changing the time step so the simulation runs at one tenth of the speed.
 author: Defold Foundation
 author: Defold Foundation
-scripts: physics.script
+scripts: physics.script, loader.script
+thumbnail: thumbnail.png
 ---
 ---
 
 
 With the physics visualization on, all collision object shapes are visible. In addition, at intersections the normals at the collision points are shown.
 With the physics visualization on, all collision object shapes are visible. In addition, at intersections the normals at the collision points are shown.
 
 
-![physics debug](physics.png)
+The example collection consists of:
+- 4 blocks with dynamic collision objects with Restituion 1.0, so they bounce forever,
+- 4 walls with static collision objects forming boundaries for the blocks,
+- game object `go` with:
+  - label with example description,
+  - a script `physics.script` included below.
+
+![physics debug](physics.png)
+
+This collection is additionally loaded via a `Collection Proxy` component in `main.collection`. Therefore, sending message `set_time_step` to its url `"main:/loader#physicsproxy"` is causing the proxy to have a different update time, causing e.g. the slow-motion effect, which might be helpful when debugging physics.
+
+![collection proxy](collectionproxy.png)

+ 11 - 0
debug/physics/example/loader.script

@@ -0,0 +1,11 @@
+function init(self)
+    msg.post(".", "acquire_input_focus")
+    msg.post("#physicsproxy", "load")
+end
+
+function on_message(self, message_id, message, sender)
+    if message_id == hash("proxy_loaded") then
+        msg.post(sender, "init")
+        msg.post(sender, "enable")
+    end
+end

+ 57 - 0
debug/physics/example/main.collection

@@ -0,0 +1,57 @@
+name: "main"
+scale_along_z: 0
+embedded_instances {
+  id: "loader"
+  data: "components {\n"
+  "  id: \"loader\"\n"
+  "  component: \"/example/loader.script\"\n"
+  "  position {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "  }\n"
+  "  rotation {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "    w: 1.0\n"
+  "  }\n"
+  "  property_decls {\n"
+  "  }\n"
+  "}\n"
+  "embedded_components {\n"
+  "  id: \"physicsproxy\"\n"
+  "  type: \"collectionproxy\"\n"
+  "  data: \"collection: \\\"/example/physics.collection\\\"\\n"
+  "exclude: false\\n"
+  "\"\n"
+  "  position {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "  }\n"
+  "  rotation {\n"
+  "    x: 0.0\n"
+  "    y: 0.0\n"
+  "    z: 0.0\n"
+  "    w: 1.0\n"
+  "  }\n"
+  "}\n"
+  ""
+  position {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+  }
+  rotation {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  scale3 {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+  }
+}

+ 2 - 2
debug/physics/example/physics.script

@@ -7,9 +7,9 @@ function on_input(self, action_id, action)
 	if action_id == hash("touch") and action.pressed then
 	if action_id == hash("touch") and action.pressed then
 		msg.post("@system:", "toggle_physics_debug") -- <3>
 		msg.post("@system:", "toggle_physics_debug") -- <3>
 		if self.show_debug then -- <4>
 		if self.show_debug then -- <4>
-			msg.post("main:/loader", "set_time_step", { factor = 1, mode = 0 })
+			msg.post("main:/loader#physicsproxy", "set_time_step", { factor = 1, mode = 0 })
 		else
 		else
-			msg.post("main:/loader", "set_time_step", { factor = 0.1, mode = 1 })
+			msg.post("main:/loader#physicsproxy", "set_time_step", { factor = 0.1, mode = 1 })
 		end
 		end
 		self.show_debug = not self.show_debug -- <5>
 		self.show_debug = not self.show_debug -- <5>
 	end
 	end

+ 1 - 1
debug/physics/game.project

@@ -3,7 +3,7 @@ title = Defold-examples
 version = 0.1
 version = 0.1
 
 
 [bootstrap]
 [bootstrap]
-main_collection = /example/physics.collectionc
+main_collection = /example/main.collectionc
 
 
 [input]
 [input]
 game_binding = /builtins/input/all.input_bindingc
 game_binding = /builtins/input/all.input_bindingc

BIN
debug/physics/thumbnail.png