kinematic.script 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. function init(self)
  2. msg.post(".", "acquire_input_focus") -- <1>
  3. self.moving = false -- <2>
  4. end
  5. local function landed(self) -- <9>
  6. self.moving = false
  7. end
  8. function on_input(self, action_id, action)
  9. if action_id == hash("touch") and action.pressed then -- <3>
  10. if not self.moving then -- <4>
  11. msg.post("#label", "disable") -- <5>
  12. self.moving = true -- <6>
  13. pos = vmath.vector3(action.x, action.y, 0) -- <7>
  14. go.animate(".", "position", go.PLAYBACK_ONCE_FORWARD, pos, go.EASING_LINEAR, 0.5, 0, landed) -- <8>
  15. end
  16. end
  17. end
  18. --[[
  19. 1. Tell the engine that this object ("." is shorthand for the current game object) should listen to input. Any input will be received in the `on_input()` function.
  20. 2. Store a flag in `self` (the current script component) to indicate if the game object is moving or not.
  21. 3. If we receive an input action named "touch" and it is pressed then run the following.
  22. 4. If the `moving` flag is not set.
  23. 5. Disable (don't show) the help text label.
  24. 6. Set the `moving` flag.
  25. 7. Create a new position called `pos` (of type `vector3`) where the user clicked.
  26. 8. Animate the game object's ("." is shorthand for the current game object) position to `pos`.
  27. When the animation is done, call the function `landed()`.
  28. 9. The function `landed()` is called when the animation is done. It just resets the `moving` flag
  29. so subsequent clicks will result in a new movement.
  30. --]]