bunny.script 953 B

1234567891011121314151617181920212223242526
  1. function init(self)
  2. local pos = go.get_position() -- <1>
  3. go.animate(".", "position.x", go.PLAYBACK_LOOP_PINGPONG, pos.x + 600, go.EASING_INOUTSINE, 6)
  4. end
  5. function on_message(self, message_id, message, sender)
  6. if message_id == hash("trigger_response") then -- <2>
  7. if message.enter then -- <3>
  8. msg.post("#sprite", "disable") -- <4>
  9. else
  10. msg.post("#sprite", "enable") -- <5>
  11. end
  12. end
  13. end
  14. --[[
  15. 1. Get the current position, then animate the position's x component
  16. looping in a ping-pong manner against an offset of 600.
  17. 2. The physics engine has detected that this game object contains
  18. collision object components that have collided with a trigger.
  19. 3. The `message` data table contains a field `enter` that is set
  20. to `true` when the trigger event signals that the trigger shape
  21. was entered. On exiting the trigger, this field is `false`.
  22. 4. Disable the sprite when the trigger is entered
  23. 5. Enable the sprite again on exit.
  24. --]]