flip.script 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. local horizontal = "bee1" -- < 1 >
  2. local vertical = "bee2"
  3. local function bee_flip(go_id) -- < 2 >
  4. if go_id == horizontal then
  5. local bee_position = go.get_position(horizontal)
  6. if bee_position.x == 400 then
  7. sprite.set_hflip("bee1#sprite", false)
  8. go.animate(horizontal,"position.x",go.PLAYBACK_ONCE_FORWARD,120,go.EASING_INOUTCUBIC,3.5,0,function()bee_flip(horizontal)end)
  9. else
  10. sprite.set_hflip("bee1#sprite", true)
  11. go.animate(horizontal,"position.x",go.PLAYBACK_ONCE_FORWARD,400,go.EASING_INOUTCUBIC,3.5,0,function()bee_flip(horizontal)end)
  12. end
  13. else
  14. local bee_position = go.get_position(vertical)
  15. if bee_position.y == 520 then
  16. sprite.set_vflip("bee2#sprite", true)
  17. go.animate(vertical,"position.y",go.PLAYBACK_ONCE_FORWARD,200,go.EASING_INOUTCUBIC,3.5,0.6,function()bee_flip(vertical)end)
  18. else
  19. sprite.set_vflip("bee2#sprite", false)
  20. go.animate(vertical,"position.y",go.PLAYBACK_ONCE_FORWARD,520,go.EASING_INOUTCUBIC,3.5,0.6,function()bee_flip(vertical)end)
  21. end
  22. end
  23. end
  24. function init(self) -- < 3 >
  25. bee_flip(horizontal)
  26. bee_flip(vertical)
  27. end
  28. --[[
  29. 1. 2 game object id's are set as local strings for horizontal and vertical examples.
  30. 2. bee_flip() function takes in the go's id then an if statement is used to determine go's
  31. position and sets horizontal or vertical flip to sprite accordingly. Then go.animate is
  32. used and a callback to bee_flip() occurs at the end of the animation.
  33. 3. In the initialize function we call bee_flip() for both horizontal and vertical bee
  34. game objects.
  35. --]]