Forráskód Böngészése

Merge branch 'defold:master' into fire_and_smoke

Pawel 2 éve
szülő
commit
141795ad2b

+ 36 - 0
examples/_main/loader.go

@@ -964,3 +964,39 @@ embedded_components {
     w: 1.0
   }
 }
+embedded_components {
+  id: "timer/repeating_timer"
+  type: "collectionproxy"
+  data: "collection: \"/examples/timer/repeating_timer/repeating_timer.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
+  }
+}
+embedded_components {
+  id: "timer/trigger_timer"
+  type: "collectionproxy"
+  data: "collection: \"/examples/timer/trigger_timer/trigger_timer.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
+  }
+}

+ 1 - 0
examples/_main/menu.gui_script

@@ -115,6 +115,7 @@ function init(self)
 	self.index["sprite"] = { "size", "tint", "flip" }
 	self.index["file"] = { "sys_save_load" }
 	self.index["tilemap"] = { "collisions", "get_set_tile" }
+	self.index["timer"] = { "repeating_timer", "trigger_timer" }
 	local categories = {}
 	for k,_ in pairs(self.index) do
 		categories[#categories + 1] = k

+ 39 - 0
examples/timer/cancel_timer/cancel_timer.collection

@@ -0,0 +1,39 @@
+name: "cancel_timer"
+scale_along_z: 0
+embedded_instances {
+  id: "go"
+  data: "components {\n"
+  "  id: \"cancel_timer\"\n"
+  "  component: \"/examples/timer/cancel_timer/cancel_timer.gui\"\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"
+  ""
+  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
+  }
+}

+ 130 - 0
examples/timer/cancel_timer/cancel_timer.gui

@@ -0,0 +1,130 @@
+script: "/examples/timer/cancel_timer/cancel_timer.gui_script"
+fonts {
+  name: "text24"
+  font: "/assets/text24.font"
+}
+background_color {
+  x: 0.0
+  y: 0.0
+  z: 0.0
+  w: 0.0
+}
+nodes {
+  position {
+    x: 360.0
+    y: 260.0
+    z: 0.0
+    w: 1.0
+  }
+  rotation {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  scale {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+  size {
+    x: 400.0
+    y: 70.0
+    z: 0.0
+    w: 1.0
+  }
+  color {
+    x: 0.101960786
+    y: 0.101960786
+    z: 0.101960786
+    w: 1.0
+  }
+  type: TYPE_TEXT
+  blend_mode: BLEND_MODE_ALPHA
+  text: "Timer triggers particle fx every 1s.\n"
+  "Click anywhere to cancel the timer."
+  font: "text24"
+  id: "info"
+  xanchor: XANCHOR_NONE
+  yanchor: YANCHOR_NONE
+  pivot: PIVOT_CENTER
+  outline {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  shadow {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+  adjust_mode: ADJUST_MODE_FIT
+  line_break: false
+  layer: ""
+  inherit_alpha: true
+  alpha: 1.0
+  outline_alpha: 0.0
+  shadow_alpha: 0.0
+  template_node_child: false
+  text_leading: 1.0
+  text_tracking: 0.0
+  custom_type: 0
+  enabled: true
+  visible: true
+}
+nodes {
+  position {
+    x: 360.0
+    y: 400.0
+    z: 0.0
+    w: 1.0
+  }
+  rotation {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  scale {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+  size {
+    x: 1.0
+    y: 1.0
+    z: 0.0
+    w: 1.0
+  }
+  color {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+  type: TYPE_PARTICLEFX
+  id: "particlefx"
+  xanchor: XANCHOR_NONE
+  yanchor: YANCHOR_NONE
+  adjust_mode: ADJUST_MODE_FIT
+  layer: ""
+  inherit_alpha: true
+  alpha: 1.0
+  template_node_child: false
+  size_mode: SIZE_MODE_AUTO
+  particlefx: "particlefx"
+  custom_type: 0
+  enabled: true
+  visible: true
+}
+material: "/builtins/materials/gui.material"
+adjust_reference: ADJUST_REFERENCE_PARENT
+max_nodes: 512
+particlefxs {
+  name: "particlefx"
+  particlefx: "/examples/timer/cancel_timer/cancel_timer.particlefx"
+}

+ 33 - 0
examples/timer/cancel_timer/cancel_timer.gui_script

@@ -0,0 +1,33 @@
+function init(self)
+	local interval = 1		-- <1>
+	local repeating = true	-- <2>
+
+	self.timer = timer.delay(interval, repeating, function()	-- <3>
+		local node = gui.get_node("particlefx")					-- <4>
+		gui.play_particlefx(node)								-- <5>
+	end)
+
+	msg.post(".", "acquire_input_focus")	-- <6>
+end
+
+function on_input(self, action_id, action)
+	if action_id == hash("touch") and action.pressed then	-- <7>
+		timer.cancel(self.timer)							-- <8>
+		local node = gui.get_node("info")					-- <9>
+		gui.set_text(node, "Timer cancelled.")				-- <10>
+	end
+end
+
+--[[
+1. We will use interval of 1 (s).
+2. We will be repeating the timer endlessly.
+3. Start the timer with interval (1s) and repeating (true) and pass a callback function.
+	Store the handle to the timer in self.timer.
+4. Get the particle fx node.
+5. Play particle fx in each call of the callback function of the timer.
+6. Tell the engine that this game object wants to receive input.
+7. If the user clicks.
+8. Cancel the timer using the saved self.timer handle.
+9. Get the text node.
+10. Update text node with an information that the timer was cancelled.
+--]]

+ 15 - 0
examples/timer/cancel_timer/cancel_timer.md

@@ -0,0 +1,15 @@
+---
+title: Cancel timer example
+brief: This example shows how to create timer and cancel it anytime, using built-in timer API.
+scripts: cancel_timer.gui_script
+---
+
+The example shows how to use Defold built-in timer and uses two indicators:
+
+1. A particlefx gui node that is triggered every 1s.
+2. A text node with an information displaying.
+
+The particle fx is played every 1s showing small eruption.
+You can click anywhere to cancel the timer and the particlefx won't be triggered anymore.
+
+![cancel_timer](cancel_timer.png)

+ 228 - 0
examples/timer/cancel_timer/cancel_timer.particlefx

@@ -0,0 +1,228 @@
+emitters {
+  id: "emitter"
+  mode: PLAY_MODE_ONCE
+  duration: 0.2
+  space: EMISSION_SPACE_WORLD
+  position {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+  }
+  rotation {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  tile_source: "/assets/sprites.atlas"
+  animation: "flame"
+  material: "/builtins/materials/particlefx.material"
+  blend_mode: BLEND_MODE_ALPHA
+  particle_orientation: PARTICLE_ORIENTATION_INITIAL_DIRECTION
+  inherit_velocity: 0.0
+  max_particle_count: 128
+  type: EMITTER_TYPE_CIRCLE
+  start_delay: 0.0
+  properties {
+    key: EMITTER_KEY_SPAWN_RATE
+    points {
+      x: 0.0
+      y: 100.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+    spread: 0.0
+  }
+  properties {
+    key: EMITTER_KEY_SIZE_X
+    points {
+      x: 0.0
+      y: 8.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+    spread: 0.0
+  }
+  properties {
+    key: EMITTER_KEY_SIZE_Y
+    points {
+      x: 0.0
+      y: 12.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+    spread: 0.0
+  }
+  properties {
+    key: EMITTER_KEY_SIZE_Z
+    points {
+      x: 0.0
+      y: 0.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+    spread: 0.0
+  }
+  properties {
+    key: EMITTER_KEY_PARTICLE_LIFE_TIME
+    points {
+      x: 0.0
+      y: 1.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+    spread: 0.0
+  }
+  properties {
+    key: EMITTER_KEY_PARTICLE_SPEED
+    points {
+      x: 0.0
+      y: 100.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+    spread: 0.0
+  }
+  properties {
+    key: EMITTER_KEY_PARTICLE_SIZE
+    points {
+      x: 0.0
+      y: 20.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+    spread: 0.0
+  }
+  properties {
+    key: EMITTER_KEY_PARTICLE_RED
+    points {
+      x: 0.0
+      y: 1.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+    spread: 0.0
+  }
+  properties {
+    key: EMITTER_KEY_PARTICLE_GREEN
+    points {
+      x: 0.0
+      y: 1.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+    spread: 0.0
+  }
+  properties {
+    key: EMITTER_KEY_PARTICLE_BLUE
+    points {
+      x: 0.0
+      y: 1.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+    spread: 0.0
+  }
+  properties {
+    key: EMITTER_KEY_PARTICLE_ALPHA
+    points {
+      x: 0.0
+      y: 1.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+    spread: 0.0
+  }
+  properties {
+    key: EMITTER_KEY_PARTICLE_ROTATION
+    points {
+      x: 0.0
+      y: 0.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+    spread: 0.0
+  }
+  particle_properties {
+    key: PARTICLE_KEY_SCALE
+    points {
+      x: 0.0
+      y: 1.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+  }
+  particle_properties {
+    key: PARTICLE_KEY_RED
+    points {
+      x: 0.0
+      y: 1.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+  }
+  particle_properties {
+    key: PARTICLE_KEY_GREEN
+    points {
+      x: 0.0
+      y: 1.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+  }
+  particle_properties {
+    key: PARTICLE_KEY_BLUE
+    points {
+      x: 0.0
+      y: 1.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+  }
+  particle_properties {
+    key: PARTICLE_KEY_ALPHA
+    points {
+      x: 0.0
+      y: 0.0
+      t_x: 0.07194582
+      t_y: 0.99740857
+    }
+    points {
+      x: 0.11320755
+      y: 0.99277455
+      t_x: 0.99418455
+      t_y: 0.10768964
+    }
+    points {
+      x: 0.7112546
+      y: 0.555656
+      t_x: 0.5694311
+      t_y: -0.82203907
+    }
+    points {
+      x: 1.0
+      y: 0.0072254334
+      t_x: 0.4737472
+      t_y: -0.8806609
+    }
+  }
+  particle_properties {
+    key: PARTICLE_KEY_ROTATION
+    points {
+      x: 0.0
+      y: 0.0
+      t_x: 1.0
+      t_y: 0.0
+    }
+  }
+  size_mode: SIZE_MODE_MANUAL
+  start_delay_spread: 0.0
+  duration_spread: 0.0
+  stretch_with_velocity: false
+  start_offset: 0.0
+  pivot {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+  }
+}

BIN
examples/timer/cancel_timer/cancel_timer.png


+ 39 - 0
examples/timer/repeating_timer/repeating_timer.collection

@@ -0,0 +1,39 @@
+name: "repeating_timer"
+scale_along_z: 0
+embedded_instances {
+  id: "go"
+  data: "components {\n"
+  "  id: \"repeating_timer\"\n"
+  "  component: \"/examples/timer/repeating_timer/repeating_timer.gui\"\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"
+  ""
+  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
+  }
+}

+ 134 - 0
examples/timer/repeating_timer/repeating_timer.gui

@@ -0,0 +1,134 @@
+script: "/examples/timer/repeating_timer/repeating_timer.gui_script"
+fonts {
+  name: "text24"
+  font: "/assets/text24.font"
+}
+background_color {
+  x: 0.0
+  y: 0.0
+  z: 0.0
+  w: 0.0
+}
+nodes {
+  position {
+    x: 363.0
+    y: 400.0
+    z: 0.0
+    w: 1.0
+  }
+  rotation {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  scale {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+  size {
+    x: 100.0
+    y: 40.0
+    z: 0.0
+    w: 1.0
+  }
+  color {
+    x: 0.101960786
+    y: 0.101960786
+    z: 0.101960786
+    w: 1.0
+  }
+  type: TYPE_TEXT
+  blend_mode: BLEND_MODE_ALPHA
+  text: "0s"
+  font: "text24"
+  id: "numeric"
+  xanchor: XANCHOR_NONE
+  yanchor: YANCHOR_NONE
+  pivot: PIVOT_CENTER
+  outline {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  shadow {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+  adjust_mode: ADJUST_MODE_FIT
+  line_break: false
+  layer: ""
+  inherit_alpha: true
+  alpha: 1.0
+  outline_alpha: 0.0
+  shadow_alpha: 0.0
+  template_node_child: false
+  text_leading: 1.0
+  text_tracking: 0.0
+  custom_type: 0
+  enabled: true
+  visible: true
+}
+nodes {
+  position {
+    x: 360.0
+    y: 400.0
+    z: 0.0
+    w: 1.0
+  }
+  rotation {
+    x: 0.0
+    y: 180.0
+    z: 90.0
+    w: 1.0
+  }
+  scale {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+  size {
+    x: 200.0
+    y: 200.0
+    z: 0.0
+    w: 1.0
+  }
+  color {
+    x: 0.0
+    y: 1.0
+    z: 0.0
+    w: 1.0
+  }
+  type: TYPE_PIE
+  blend_mode: BLEND_MODE_ALPHA
+  texture: ""
+  id: "radial"
+  xanchor: XANCHOR_NONE
+  yanchor: YANCHOR_NONE
+  pivot: PIVOT_CENTER
+  adjust_mode: ADJUST_MODE_FIT
+  layer: ""
+  inherit_alpha: true
+  outerBounds: PIEBOUNDS_ELLIPSE
+  innerRadius: 90.0
+  perimeterVertices: 120
+  pieFillAngle: 360.0
+  clipping_mode: CLIPPING_MODE_NONE
+  clipping_visible: true
+  clipping_inverted: false
+  alpha: 1.0
+  template_node_child: false
+  size_mode: SIZE_MODE_MANUAL
+  custom_type: 0
+  enabled: true
+  visible: true
+}
+material: "/builtins/materials/gui.material"
+adjust_reference: ADJUST_REFERENCE_PARENT
+max_nodes: 512

+ 36 - 0
examples/timer/repeating_timer/repeating_timer.gui_script

@@ -0,0 +1,36 @@
+-- set value of numeric time indicator (from 0 to 60s)
+local function update_numeric(p)
+	local node = gui.get_node("numeric")
+	gui.set_text(node, tostring(p) .. "s")
+end
+
+-- update radial/circle time indicator by changing the fill angle
+local function update_radial(p)
+	local node = gui.get_node("radial")
+	local angle = p * 6
+	gui.set_fill_angle(node, angle)
+end
+
+function init(self)
+	self.count = 0			-- <1>
+	local interval = 1		-- <2>
+	local repeating = true	-- <3>
+
+	timer.delay(interval, repeating, function()		-- <4>
+		self.count = self.count + 1					-- <5>
+		local p = self.count % 60					-- <6>
+		update_numeric(p)							-- <7>
+		update_radial(p)							-- <8>
+	end)
+end
+
+--[[
+1. Start the count with value 0.
+2. We will use interval of 1 [s].
+3. We will be repeating the timer endlessly.
+4. Start the timer with interval (1s) and repeating (true) and pass a callback function.
+5. The function will be called every 1s, so increase the count by 1 each time.
+6. Get the modulo of 60, because the timer will be reset every 60s.
+7. Update the numeric display of seconds passed.
+8. Update the radial indicator of seconds passed.
+--]]

+ 14 - 0
examples/timer/repeating_timer/repeating_timer.md

@@ -0,0 +1,14 @@
+---
+title: Repeating timer example
+brief: This example shows how to create timer that repeats endlessly every second
+scripts: repeating_timer.gui_script
+---
+
+The example shows how to use Defold built-in timer and uses two indicators:
+
+1. A numerical time text with seconds counter created using a text node
+2. A circular time indicator created using a pie node
+
+The timer trigers updates of those two indicators every 1s to form a counter.
+
+![repeating_timer](repeating_timer.png)

BIN
examples/timer/repeating_timer/repeating_timer.png


+ 39 - 0
examples/timer/trigger_timer/trigger_timer.collection

@@ -0,0 +1,39 @@
+name: "trigger_timer"
+scale_along_z: 0
+embedded_instances {
+  id: "go"
+  data: "components {\n"
+  "  id: \"trigger_timer\"\n"
+  "  component: \"/examples/timer/trigger_timer/trigger_timer.gui\"\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"
+  ""
+  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
+  }
+}

+ 145 - 0
examples/timer/trigger_timer/trigger_timer.gui

@@ -0,0 +1,145 @@
+script: "/examples/timer/trigger_timer/trigger_timer.gui_script"
+fonts {
+  name: "text24"
+  font: "/assets/text24.font"
+}
+background_color {
+  x: 0.0
+  y: 0.0
+  z: 0.0
+  w: 0.0
+}
+nodes {
+  position {
+    x: 360.0
+    y: 430.0
+    z: 0.0
+    w: 1.0
+  }
+  rotation {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  scale {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+  size {
+    x: 100.0
+    y: 40.0
+    z: 0.0
+    w: 1.0
+  }
+  color {
+    x: 0.101960786
+    y: 0.101960786
+    z: 0.101960786
+    w: 1.0
+  }
+  type: TYPE_TEXT
+  blend_mode: BLEND_MODE_ALPHA
+  text: "0"
+  font: "text24"
+  id: "counter"
+  xanchor: XANCHOR_NONE
+  yanchor: YANCHOR_NONE
+  pivot: PIVOT_CENTER
+  outline {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  shadow {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+  adjust_mode: ADJUST_MODE_FIT
+  line_break: false
+  layer: ""
+  inherit_alpha: true
+  alpha: 1.0
+  outline_alpha: 0.0
+  shadow_alpha: 0.0
+  template_node_child: false
+  text_leading: 1.0
+  text_tracking: 0.0
+  custom_type: 0
+  enabled: true
+  visible: true
+}
+nodes {
+  position {
+    x: 360.0
+    y: 260.0
+    z: 0.0
+    w: 1.0
+  }
+  rotation {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  scale {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+  size {
+    x: 600.0
+    y: 80.0
+    z: 0.0
+    w: 1.0
+  }
+  color {
+    x: 0.101960786
+    y: 0.101960786
+    z: 0.101960786
+    w: 1.0
+  }
+  type: TYPE_TEXT
+  blend_mode: BLEND_MODE_ALPHA
+  text: "Counter ticks every 1s.\n"
+  "Click to trigger timer callback asynchronously."
+  font: "text24"
+  id: "info"
+  xanchor: XANCHOR_NONE
+  yanchor: YANCHOR_NONE
+  pivot: PIVOT_CENTER
+  outline {
+    x: 0.0
+    y: 0.0
+    z: 0.0
+    w: 1.0
+  }
+  shadow {
+    x: 1.0
+    y: 1.0
+    z: 1.0
+    w: 1.0
+  }
+  adjust_mode: ADJUST_MODE_FIT
+  line_break: false
+  layer: ""
+  inherit_alpha: true
+  alpha: 1.0
+  outline_alpha: 0.0
+  shadow_alpha: 0.0
+  template_node_child: false
+  text_leading: 1.0
+  text_tracking: 0.0
+  custom_type: 0
+  enabled: true
+  visible: true
+}
+material: "/builtins/materials/gui.material"
+adjust_reference: ADJUST_REFERENCE_PARENT
+max_nodes: 512

+ 33 - 0
examples/timer/trigger_timer/trigger_timer.gui_script

@@ -0,0 +1,33 @@
+function init(self)
+	self.count = 0			-- <1>
+	local interval = 1		-- <2>
+	local repeating = true	-- <3>
+
+	self.timer = timer.delay(interval, repeating, function()	-- <4>
+		self.count = self.count + 1								-- <5>
+		local node = gui.get_node("counter")					-- <6>
+		gui.set_text(node, self.count)							-- <7>
+	end)
+
+	msg.post(".", "acquire_input_focus")	-- <8>
+end
+
+function on_input(self, action_id, action)
+	if action_id == hash("touch") and action.pressed then	-- <9>
+		timer.trigger(self.timer)							-- <10>
+	end
+end
+
+--[[
+1. Start the count with value 0.
+2. We will use interval of 1 [s].
+3. We will be repeating the timer endlessly.
+4. Start the timer with interval (1s) and repeating (true) and pass a callback function.
+	Store the handle to the timer in self.timer.
+5. The function will be called every 1s, so increase the count by 1 each time.
+6. Get the counter text node.
+7. Update the counter text node with an increased count.
+8. Tell the engine that this game object wants to receive input.
+9. If the user clicks.
+10. Trigger the timer's callback function asynchronously using the saved self.timer handle.
+--]]

+ 15 - 0
examples/timer/trigger_timer/trigger_timer.md

@@ -0,0 +1,15 @@
+---
+title: Trigger timer example
+brief: This example shows how to create timer that triggers counting every 1s and can be triggered manually and asynchronously as a reaction to user input.
+scripts: trigger_timer.gui_script
+---
+
+The example shows how to use Defold built-in timer and trigger it asynchronously and uses two indicators:
+
+1. A counter text increased every 1s created using a text node.
+2. A text node with information displayed.
+
+The timer triggers update of the counter every 1s.
+Click anywhere to trigger the callback of the timer asynchronously.
+
+![trigger_timer](trigger_timer.png)

BIN
examples/timer/trigger_timer/trigger_timer.png


+ 1 - 1
game.project

@@ -1,7 +1,7 @@
 [project]
 title = Defold-examples
 version = 0.1
-dependencies#0 = https://github.com/defold/extension-spine/archive/refs/tags/2.0.4.zip
+dependencies#0 = https://github.com/defold/extension-spine/archive/refs/tags/2.3.1.zip
 
 [bootstrap]
 main_collection = /examples/main.collectionc