pointer_over.gui_script 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. function init(self)
  2. msg.post(".", "acquire_input_focus") -- <1>
  3. self.button = gui.get_node("button") -- <2>
  4. self.text = gui.get_node("text") -- <3>
  5. self.is_over = false -- <4>
  6. end
  7. function on_input(self, action_id, action)
  8. if action_id == nil then --<5>
  9. if gui.pick_node(self.button, action.x, action.y) then -- <6>
  10. if not self.is_over then
  11. gui.set_text(self.text, "HELLO!") -- <7>
  12. self.is_over = true
  13. end
  14. else
  15. if self.is_over then
  16. gui.set_text(self.text, "BUTTON") -- <8>
  17. self.is_over = false
  18. end
  19. end
  20. end
  21. end
  22. --[[
  23. 1. Tell the engine that this game object wants to receive input.
  24. 2. Get the instance for the node named "button" (the button box).
  25. 3. Get the instance for the node named "text" (the button label).
  26. 4. Trigger for locking multiple execution.
  27. 5. If action_id equal nil (pointer is moving)
  28. 6. Check if the pointer position (`action.x` and `action.y`) is within the boundaries of
  29. the button node.
  30. 7. Change the label text in pointer over case.
  31. 8. Change the label text to default value.
  32. --]]