bunny.script 860 B

123456789101112131415161718192021222324
  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 pos = vmath.vector3(action.x, action.y, 0) -- <3>
  7. local carrot_id = factory.create("#carrotfactory", pos) -- <4>
  8. go.animate(carrot_id, "euler.z", go.PLAYBACK_ONCE_FORWARD, 360, go.EASING_LINEAR, 1, 0, function() -- <5>
  9. go.delete(carrot_id) -- <6>
  10. end)
  11. end
  12. end
  13. --[[
  14. 1. Acquire input focus so we get input from the engine.
  15. 2. If the user clicks.
  16. 3. Set the spawning position to the mouse click position.
  17. 4. Tell the component "carrotfactory" ("#" denotes a component in the
  18. current game object) to spawn a game object according to its prototype.
  19. The function returns the id of the new game object.
  20. 5. Rotate the new game object.
  21. 6. Delete the game object
  22. --]]