-- Sound Fade Behavior -- This script is compatible with Director 6 and 7. -- Paste this script into a Behavior (Score) script. -- (Watch out for long line breaks). -- Then drop the Behavior into the script channel. -- Copyright. Bruce A. Epstein. All Rights Reserved. -- Version 1.0, June 18, 1999 -- http://www.zeusprod.com/nutshell/fade.html property pSoundChannel, pBegin, pStart, pEnd, pDuration, pStartTime property pChangePerTick, pTight, pWait -- Initialization on beginSprite me -- Record starting time for later calculations set pStartTime = the ticks -- If user didn't specify a starting volume, use the current volume if pBegin then set pStart = the volume of sound pSoundChannel end if -- Jump abruptly to the starting volume if necessary if the volume of sound pSoundChannel <> pStart then set the volume of sound pSoundChannel = pStart end if -- Calculate how much to change the volume in each tick of time set pChangePerTick = float(pEnd - pStart)/pDuration end beginSprite on endSprite me -- Set the ending volume even if rounding errors left it at an inexact level set the volume of sound pSoundChannel = pEnd end endSprite on exitFrame me -- Fade the sound up or down between the starting and ending volumes. -- There are several possible modes for waiting: -- If pTight is TRUE, we'll create a tight repeat loop and fade the sound -- If pTight is FALSE, we'll adjust the volume once per exitFrame event -- If pWait is TRUE, we'll also wait in the frame until the sound fade completes -- If pTight and pWait are both FALSE, the sound will fade for the number of -- frames over which the script is tweened. When leaving the sprite span -- the ending volume will may be set abruptly in that case. if pTight then -- pTight is TRUE, so we'll create a tight repeat loop and fade the sound repeat while not done(me) set elapsed = the ticks - pStartTime set the volume of sound pSoundChannel = pStart + elapsed * pChangePerTick end repeat else -- pTight is FALSE, so we'll adjust the volume once per exitFrame event set elapsed = the ticks - pStartTime set the volume of sound pSoundChannel = pStart + elapsed * pChangePerTick -- If desired, wait in the frame until the final volume is achieved if pWait and not done (me) then go the frame end if end if end exitFrame on done me -- Check if the sound fade is done. -- Returns TRUE when we reach or pass the volume of interest if (pStart > pEnd) and (the volume of sound pSoundChannel > pEnd) then return FALSE else if (pStart < pEnd) and (the volume of sound pSoundChannel < pEnd) then return FALSE else return TRUE end if end done on getBehaviorDescription me set intro = "-- Sound Fade Behavior by Bruce A. Epstein. Copyright 1999. All rights reserved. " & RETURNs(1) put "-- See Chapter 15 of Director in a Nutshell and http://www.zeusprod.com/nutshell/fade.html" & RETURNs(2) after INTRO put "Parameters:" & RETURNs(1) after INTRO set desc1 = "-- pSoundChannel - sound channel to fade (from 1 to 8). Only one channel can be faded at a time." & RETURNs(2) set desc2 = "-- pBegin - if TRUE, fade begins from current volume, and pStart is ignored." & RETURNs(2) set desc3 = "-- pStart - starting volume for fade (0-255). If pBegin is TRUE, this parameter is ignored. " & RETURNs(2) set desc4 = "-- pEnd - ending volume for fade (0-255). Automatically fades up or down, depending on relation to pStart." & RETURNs(2) set desc5 = "-- pDuration - number of ticks over which to create fade. Default is 180 ticks (3 seconds)." & RETURNs(2) set desc6 = "-- pTight - if TRUE, sound fade is performed in a tight repeat loop, locking out animation and screen updates. If FALSE, sound is faded incrementally each time exitFrame event is sent." & RETURNs(2) set desc7 = "-- pWait - if TRUE, wait in the frame until the sound fade completes. If pTight is FALSE and pWait is FALSE, the sound will change over the range of frames over which the script is tween. pWait is irrelevant if pTight is TRUE." & RETURNs(2) set desc = intro & desc1 & desc2 & desc3 & desc4 & desc5 & desc6 & desc7 return desc end on returns n set retString = RETURN repeat with x = 2 to n put RETURN after retString end repeat return retString end on getPropertyDescriptionList me set param1 = [#default: 1, #format:#integer, #range:[1,2,3,4,5,6,7,8], #comment: "Sound Channel"] set param2 = [#default: TRUE, #format:#boolean, #comment: "Start from Current Volume"] set param3 = [#default: 0, #format:#integer, #range:[#min:0, #max:255], #comment: "Start Volume"] set param4 = [#default: 255, #format:#integer, #range:[#min:0, #max:255], #comment: "End Volume"] set param5 = [#default: 180, #format:#integer, #range:[#min:0, #max:600],#comment: "Duration in ticks"] set param6 = [#default: FALSE, #format:#boolean, #comment: "Tight Repeat loop"] set param7 = [#default: TRUE, #format:#boolean, #comment: "Wait in frame"] return [#pSoundChannel:param1, #pBegin:param2, #pstart:param3, #pEnd:param4, #pDuration:param5, #pTight:param6, #pWait:param7] end getPropertyDescriptionList
Zeus Home Page | LIAN
TOC | DIAN
TOC | Links | E-Mail
Place an Order | Downloads
| FAQ | GuestBook
| Glossary
Copyright © 1996-1999. Bruce A. Epstein. All Rights Reserved.
(The page last revised June 18, 1999)