Jelajahi Sumber

Merge branch 'AGulev-master'

Mikael Säker 8 tahun lalu
induk
melakukan
2476bb96a6

+ 24 - 6
examples/_main/loader.go

@@ -29,9 +29,9 @@ components {
   }
 }
 embedded_components {
-  id: "basics/simple move"
+  id: "basics/simple_move"
   type: "collectionproxy"
-  data: "collection: \"/examples/basics/simple move/simple move.collection\"\n"
+  data: "collection: \"/examples/basics/simple_move/simple_move.collection\"\n"
   "exclude: false\n"
   ""
   position {
@@ -65,9 +65,9 @@ embedded_components {
   }
 }
 embedded_components {
-  id: "basics/message passing"
+  id: "basics/message_passing"
   type: "collectionproxy"
-  data: "collection: \"/examples/basics/message passing/message passing.collection\"\n"
+  data: "collection: \"/examples/basics/message_passing/message_passing.collection\"\n"
   "exclude: false\n"
   ""
   position {
@@ -101,9 +101,9 @@ embedded_components {
   }
 }
 embedded_components {
-  id: "basics/parent child"
+  id: "basics/parent_child"
   type: "collectionproxy"
-  data: "collection: \"/examples/basics/parent child/parent child.collection\"\n"
+  data: "collection: \"/examples/basics/parent_child/parent_child.collection\"\n"
   "exclude: false\n"
   ""
   position {
@@ -352,3 +352,21 @@ embedded_components {
     w: 1.0
   }
 }
+embedded_components {
+  id: "input/down_duration"
+  type: "collectionproxy"
+  data: "collection: \"/examples/input/down_duration/down_duration.collection\"\n"
+  "exclude: false\n"
+  ""
+  position {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+  }
+  rotation {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+}

+ 2 - 2
examples/_main/menu.gui_script

@@ -100,11 +100,11 @@ end
 
 function init(self)
 	self.index = { "basics", "physics", "animation", "gui", "input", "audio", "render", "camera", "debug" }
-	self.index["basics"] = { "simple move", "message passing", "follow", "parent child", "spawn" }
+	self.index["basics"] = { "simple_move", "message_passing", "follow", "parent_child", "spawn" }
 	self.index["physics"] = { "dynamic", "kinematic", "trigger" }
 	self.index["animation"] = { "spinner", "flipbook", "tween", "spine" }
 	self.index["gui"] = { "button", "stencil" }
-	self.index["input"] = { "move", "text" }
+	self.index["input"] = { "move", "text", "down_duration" }
 	self.index["audio"] = { "lorem ipsum" }
 	self.index["render"] = { "lorem ipsum" }
 	self.index["camera"] = { "lorem ipsum" }

+ 0 - 1
examples/_main/ui.gui_script

@@ -1,7 +1,6 @@
 function init(self)
 	self.closenode = gui.get_node("close")
 	msg.post("#", "hide")
-	msg.post("#", "acquire_input_focus")
 end
 
 function on_message(self, message_id, message, sender)

+ 0 - 0
examples/basics/message passing/bunny1.script → examples/basics/message_passing/bunny1.script


+ 0 - 0
examples/basics/message passing/bunny2.script → examples/basics/message_passing/bunny2.script


+ 2 - 2
examples/basics/message passing/message passing.collection → examples/basics/message_passing/message_passing.collection

@@ -4,7 +4,7 @@ embedded_instances {
   id: "bunny 1"
   data: "components {\n"
   "  id: \"script\"\n"
-  "  component: \"/examples/basics/message passing/bunny1.script\"\n"
+  "  component: \"/examples/basics/message_passing/bunny1.script\"\n"
   "  position {\n"
   "    x: 0.0\n"
   "    y: 0.0\n"
@@ -113,7 +113,7 @@ embedded_instances {
   id: "bunny 2"
   data: "components {\n"
   "  id: \"script\"\n"
-  "  component: \"/examples/basics/message passing/bunny2.script\"\n"
+  "  component: \"/examples/basics/message_passing/bunny2.script\"\n"
   "  position {\n"
   "    x: 0.0\n"
   "    y: 0.0\n"

+ 0 - 0
examples/basics/message passing/message passing.md → examples/basics/message_passing/message_passing.md


+ 0 - 0
examples/basics/message passing/message_passing.png → examples/basics/message_passing/message_passing.png


+ 0 - 5
examples/basics/parent child/parent child

@@ -1,5 +0,0 @@
----
-title: A game object follows input
-brief: This example shows how to make a game object move to the position the user clicks.
-scripts: follow.script
----

+ 0 - 0
examples/basics/parent child/child.script → examples/basics/parent_child/child.script


+ 0 - 0
examples/basics/parent child/parent.script → examples/basics/parent_child/parent.script


+ 2 - 2
examples/basics/parent child/parent child.collection → examples/basics/parent_child/parent_child.collection

@@ -5,7 +5,7 @@ embedded_instances {
   children: "child"
   data: "components {\n"
   "  id: \"script\"\n"
-  "  component: \"/examples/basics/parent child/parent.script\"\n"
+  "  component: \"/examples/basics/parent_child/parent.script\"\n"
   "  position {\n"
   "    x: 0.0\n"
   "    y: 0.0\n"
@@ -114,7 +114,7 @@ embedded_instances {
   id: "child"
   data: "components {\n"
   "  id: \"script\"\n"
-  "  component: \"/examples/basics/parent child/child.script\"\n"
+  "  component: \"/examples/basics/parent_child/child.script\"\n"
   "  position {\n"
   "    x: 0.0\n"
   "    y: 0.0\n"

+ 0 - 0
examples/basics/parent child/parent child.md → examples/basics/parent_child/parent_child.md


+ 0 - 0
examples/basics/parent child/parent_child.png → examples/basics/parent_child/parent_child.png


+ 1 - 1
examples/basics/simple move/simple move.collection → examples/basics/simple_move/simple_move.collection

@@ -4,7 +4,7 @@ embedded_instances {
   id: "gameobject"
   data: "components {\n"
   "  id: \"script\"\n"
-  "  component: \"/examples/basics/simple move/simple move.script\"\n"
+  "  component: \"/examples/basics/simple_move/simple_move.script\"\n"
   "  position {\n"
   "    x: 0.0\n"
   "    y: 0.0\n"

+ 1 - 1
examples/basics/simple move/simple move.md → examples/basics/simple_move/simple_move.md

@@ -1,7 +1,7 @@
 ---
 title: Moving game object
 brief: This example shows how to move a game object.
-scripts: simple move.script
+scripts: simple_move.script
 ---
 
 ![simple move](simple_move.png)

+ 0 - 0
examples/basics/simple move/simple_move.png → examples/basics/simple_move/simple_move.png


+ 0 - 0
examples/basics/simple move/simple move.script → examples/basics/simple_move/simple_move.script


TEMPAT SAMPAH
examples/input/down_duration/down_click.png


+ 111 - 0
examples/input/down_duration/down_duration.collection

@@ -0,0 +1,111 @@
+name: "default"
+scale_along_z: 0
+embedded_instances {
+  id: "bunny"
+  data: "components {\n"
+  "  id: \"script\"\n"
+  "  component: \"/examples/input/down_duration/down_duration.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"
+  "}\n"
+  "embedded_components {\n"
+  "  id: \"sprite\"\n"
+  "  type: \"sprite\"\n"
+  "  data: \"tile_set: \\\"/assets/sprites.atlas\\\"\\n"
+  "default_animation: \\\"bunny2_ready\\\"\\n"
+  "material: \\\"/builtins/materials/sprite.material\\\"\\n"
+  "blend_mode: BLEND_MODE_ALPHA\\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"
+  "embedded_components {\n"
+  "  id: \"label\"\n"
+  "  type: \"label\"\n"
+  "  data: \"size {\\n"
+  "  x: 128.0\\n"
+  "  y: 32.0\\n"
+  "  z: 0.0\\n"
+  "  w: 0.0\\n"
+  "}\\n"
+  "scale {\\n"
+  "  x: 0.5\\n"
+  "  y: 0.5\\n"
+  "  z: 1.0\\n"
+  "  w: 0.0\\n"
+  "}\\n"
+  "color {\\n"
+  "  x: 0.0\\n"
+  "  y: 0.5647059\\n"
+  "  z: 0.99215686\\n"
+  "  w: 1.0\\n"
+  "}\\n"
+  "outline {\\n"
+  "  x: 1.0\\n"
+  "  y: 1.0\\n"
+  "  z: 1.0\\n"
+  "  w: 1.0\\n"
+  "}\\n"
+  "shadow {\\n"
+  "  x: 1.0\\n"
+  "  y: 1.0\\n"
+  "  z: 1.0\\n"
+  "  w: 1.0\\n"
+  "}\\n"
+  "leading: 1.0\\n"
+  "tracking: 0.0\\n"
+  "pivot: PIVOT_W\\n"
+  "blend_mode: BLEND_MODE_ALPHA\\n"
+  "line_break: false\\n"
+  "text: \\\"Click...\\\"\\n"
+  "font: \\\"/assets/text48.font\\\"\\n"
+  "material: \\\"/builtins/fonts/label.material\\\"\\n"
+  "\"\n"
+  "  position {\n"
+  "    x: 20.653\n"
+  "    y: 118.002\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: 132.102
+    y: 360.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
+  }
+}

+ 9 - 0
examples/input/down_duration/down_duration.md

@@ -0,0 +1,9 @@
+---
+title: Down duration
+brief: Listens to text input trigger "click" and count mouse down duration in update method.
+scripts: down_duration.script
+---
+
+![input bindings](input_binding.png)
+
+![text](down_click.png)

+ 49 - 0
examples/input/down_duration/down_duration.script

@@ -0,0 +1,49 @@
+function init(self)
+	msg.post(".", "acquire_input_focus") -- <1>
+	self.message = "Duration: %f . Last duration: %f" -- <2>
+	self.duration = 0
+	self.last_duration = 0
+end
+
+local function update_text(self) -- <3>
+	local msg = string.format(self.message, self.duration, self.last_duration) -- <4>
+	label.set_text("#label", msg) -- <5>
+end
+
+function on_input(self, action_id, action)
+	if action_id == hash("click") then -- <6>
+		if action.pressed then -- <7>
+			self.is_start_timer = true -- <8>
+		elseif action.released then -- <9>
+			self.is_start_timer = false -- <10>
+			self.last_duration = self.duration -- <11>
+			self.duration = 0
+			update_text(self) -- <12>
+		end
+	end
+end
+
+function update(self, dt)
+	if self.is_start_timer then -- <13>
+		self.duration = self.duration + dt -- <14>
+		update_text(self) -- <15>
+	end
+end
+
+--[[
+1. Tell the engine that this object ("." is shorthand for the current game object) wants to receive input. The function `on_input()` will be called whenever input is received.
+2. Prepare format of output including two float placeholders.
+3. Create method for updating the text label.
+4. Create a formatted string from the format and duration and last_duration arguments.
+5. Set the label component to the stored text.
+6. Check if we receive an input action named "click".
+7. Check if it is pressed then run the following.
+8. Change flag for starting a timer.
+9. Check if it is released then run the following.
+10. Change flag for stopping a timer.
+11. Save duration as last_duration.
+12. Run method for updating text.
+13. Check if timer is started.
+14. Add dt (delta time from the last frame) to the duration variable.
+15. Run method for updating text.
+--]]

TEMPAT SAMPAH
examples/input/down_duration/input_binding.png