fade_in_out.script 823 B

12345678910111213141516171819202122
  1. local TIME = 2 -- <1>
  2. local DELAY = 1 -- <2>
  3. function init(self)
  4. sound.play("#music", { gain = 1.0 }) -- <3>
  5. msg.post("#", "fade_in_out") -- <4>
  6. end
  7. function on_message(self, message_id, message, sender)
  8. if message_id == hash("fade_in_out") then
  9. go.animate("#music", "gain", go.PLAYBACK_LOOP_PINGPONG, 0, go.EASING_LINEAR, TIME, DELAY) -- <5>
  10. end
  11. end
  12. --[[
  13. 1. Create TIME constant - duration of the fade-in and fade-out effect.
  14. 2. Create DELAY constant - pause before the start of the fade-in and fade-out effect.
  15. 3. Tell the component "#music" to start playing its sound with a gain of 1.0
  16. 4. Send a "fade_in_out" message to the script telling it to start fading the music in and out
  17. 5. Animate the "gain" property of the sound component back and forth between 0 and the current value (1.0)
  18. --]]