cancel_timer.gui_script 1.1 KB

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