get_set_font.script 891 B

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