button.gui_script 900 B

1234567891011121314151617181920212223242526
  1. function init(self)
  2. msg.post(".", "acquire_input_focus") -- <1>
  3. end
  4. function on_input(self, action_id, action)
  5. if action_id == hash("touch") and action.pressed then -- <2>
  6. local button = gui.get_node("button") -- <3>
  7. local text = gui.get_node("text") -- <4>
  8. if gui.pick_node(button, action.x, action.y) then -- <5>
  9. gui.set_text(text, "HELLO!") -- <6>
  10. else
  11. gui.set_text(text, "CLICK ME!") -- <7>
  12. end
  13. end
  14. end
  15. --[[
  16. 1. Tell the engine that this game object wants to receive input.
  17. 2. If the user clicks.
  18. 3. Get the instance for the node named "button" (the button box).
  19. 4. Get the instance for the node named "text" (the button label).
  20. 5. Check if the click position (`action.x` and `action.y`) is within the boundaries of
  21. the button node.
  22. 6. If the user clicks on the button, change the label text.
  23. 7. If the user clicks elsewhere, change the label text to something else.
  24. --]]