spaceship.script 1.2 KB

123456789101112131415161718192021222324252627282930
  1. local up_down -- <1>
  2. local left_right
  3. function up_down(self) -- <2>
  4. go.animate(".", "position.y", go.PLAYBACK_ONCE_PINGPONG, 624, go.EASING_INOUTSINE, 2, 0, left_right)
  5. end
  6. function left_right(self) -- <3>
  7. go.animate(".", "position.x", go.PLAYBACK_ONCE_PINGPONG, 660, go.EASING_INOUTSINE, 2, 0, up_down)
  8. end
  9. function init(self)
  10. up_down(self) -- <4>
  11. go.animate(".", "scale.y", go.PLAYBACK_LOOP_PINGPONG, 0.5, go.EASING_INOUTSINE, 1) -- <5>
  12. go.animate("#sprite", "tint.x", go.PLAYBACK_LOOP_PINGPONG, 0.0, go.EASING_INOUTSINE, 1.5) -- <6>
  13. end
  14. --[[
  15. 1. In Lua, local variables must be declared prior to their use.
  16. Since the functions `up_down()` and `left_right()` refer to
  17. each other we "forward declare" the names `up_down` and
  18. `left_right` before the function definitions.
  19. 2. This function animates the game object position's y component,
  20. then calls the function `left_right()` on completion.
  21. 3. This function animates the game object position's x component,
  22. then calls the function `up_down()` on completion.
  23. 4. Start by calling the `up_down()` function.
  24. 5. In parallel, tween the scale y component.
  25. 6. And the sprite's tint x component (which is the red value).
  26. --]]