get_set_material.script 987 B

1234567891011121314151617181920212223242526
  1. -- create a script resource property 'myfont' referencing a font file
  2. go.property("mymaterial", resource.material("/example/get_set_material.material"))
  3. function init(self)
  4. msg.post(".", "acquire_input_focus")
  5. -- get the material file on the gui component which is assigned to
  6. -- the material with id 'default'
  7. self.default_texture = go.get("#gui", "materials", { key = "default" })
  8. end
  9. function on_input(self, action_id, action)
  10. if action_id == hash("mouse_button_left") and action.pressed then
  11. -- get the material file currently assigned to the material with id 'default'
  12. local current_texture = go.get("#gui", "materials", { key = "default" })
  13. -- toggle between the default material and the material referenced by the
  14. -- script resource property 'default'
  15. if current_texture == self.mymaterial then
  16. go.set("#gui", "materials", self.default_texture, { key = "default" })
  17. else
  18. go.set("#gui", "materials", self.mymaterial, { key = "default" })
  19. end
  20. end
  21. end