get_set_texture.script 929 B

1234567891011121314151617181920212223242526
  1. -- create a script resource property 'myatlas' referencing an atlas file
  2. go.property("myatlas", resource.atlas("/example/get_set_texture.atlas"))
  3. function init(self)
  4. msg.post(".", "acquire_input_focus")
  5. -- get the atlas file on the gui component which is assigned to
  6. -- the atlas/texture with id 'ui'
  7. self.default_atlas = go.get("#gui", "textures", { key = "ui" })
  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 atlas file currently assigned to the atlas/texture with id 'ui'
  12. local current_atlas = go.get("#gui", "textures", { key = "ui" })
  13. -- toggle between the default texture and the texture referenced by the
  14. -- script resource property 'ui'
  15. if current_atlas == self.myatlas then
  16. go.set("#gui", "textures", self.default_atlas, { key = "ui" })
  17. else
  18. go.set("#gui", "textures", self.myatlas, { key = "ui" })
  19. end
  20. end
  21. end