spine.script 1.2 KB

123456789101112131415161718192021222324252627
  1. function init(self)
  2. msg.post(".", "acquire_input_focus") -- <1>
  3. self.state = "idle" -- <2>
  4. end
  5. function on_input(self, action_id, action)
  6. if action_id == hash("touch") and action.pressed then
  7. local properties = { blend_duration = 0.3 } -- <3>
  8. if self.state == "idle" then -- <4>
  9. spine.play_anim("#spinemodel", hash("run"), go.PLAYBACK_LOOP_FORWARD, properties)
  10. label.set_text("#label", "Click to idle...")
  11. self.state = "run"
  12. elseif self.state == "run" then -- <5>
  13. spine.play_anim("#spinemodel", hash("idle"), go.PLAYBACK_LOOP_FORWARD, properties)
  14. label.set_text("#label", "Click to run...")
  15. self.state = "idle"
  16. end
  17. end
  18. end
  19. --[[
  20. 1. Tell the engine that this game object (".", which is shorthand for the current game object) should receive input.
  21. 2. Store state for this instance. Use a string that will be either "idle" or "run", reflecting the animation.
  22. 3. If user clicks, set up animation properties. Blend duration larger that 0 to get smoother transition between animations.
  23. 4. If state is currently "idle", play "run" animation, change text on label and change the state variable to "run".
  24. 5. If state is currently "run", play "idle" animation, change text on label and change the state variable to "idle".
  25. --]]