Articles Archive
Articles Search
Director Wiki
 

Making Your Own Film Loops

March 5, 2001
by Will Turnage

Dear Multimedia Handyman,

I'm busy with a CD-ROM where I need to use a lot of film loops I am having trouble though testing whether a film loop has finished playing. I need to place a film loop in the score as a single-frame sprite, and then be able to test whether the film loop has finished playing. When it has finished playing, the playback head must continue to the next film loop and so on...

Thanks

David

Dear David,

Using Film Loops and Animated GIFs in your Director project is a quick and easy way to compact animations in the score. Their biggest downside, though, is that once they're created you have very little control over them. You can't control their speed or the number of times they loop, and you can't start and stop the animation. However, you can easily create this functionality with a single behavior. You still get the benefits of film loops -- that is, the end result only takes up one sprite in your score -- but now you'll have much more control over how the loop runs.

To create this behavior, you should first define what you need it to do. In this instance, the behavior will have four basic control features. They are:

In order for your behavior to work, the first thing it has to do is to collect all of the members that go in the film loop. One of the easiest ways to do this is by putting a common word in the name of each cast member in the loop. So you could name the members of your film loop IntroFilmLoop,1, IntroFilmLoop,2, and so on, and the behavior will just look through your entire movie for the word IntroFilmLoop in a cast member's name. If it finds it, then it adds it to the loop. For instance:

on beginSprite me

  pMemberList = []
  tempCastCount = the number of castlibs
  repeat with i = 1 to tempCastCount
    tempMemCount = the number of members of castlib i
    repeat with j = 1 to tempMemCount
      if member (j,i).name contains "IntroFilmLoop" and member (j,i).type = #bitmap then
        pMemberList.append (member (j, i))
      end if
    end repeat
  end repeat
  pLoopCount = 0
  pCurrentMember = 1
  pFrameCounter = 0
  sprite (me.spriteNum).member = pMemberList[pCurrentMember]

end

This handler initializes all the variables in your behavior. It starts by finding the number of casts in your movie, and then for each cast it finds out how many members are in that cast. Next it checks each member in every cast for two requirements: that it's a bitmap, and that its name contains the string "IntroFilmLoop". If the member meets both of those requirements, then it gets added to the list of members that make up the film loop. Finally, the handler initializes some variables, that is, it sets the number of loops to zero, it sets the number of frames executed to zero, and it sets the sprite's member equal to the first member in the film loop list.

Next, you need to create some code that will execute every frame to control the appearance and speed of the film loop, as well as keep track of how many loops and frames have elapsed. For example:

on exitFrame me

  if pPlaying then
    pFrameCounter = pFrameCounter + 1
    if pFrameCounter >= pFrameSpeed then
      pFrameCounter = 0
      pCurrentMember = pCurrentMember + 1
      if pCurrentMember > pMemberList.count then
        pCurrentMember = 1
        pLoopCount = pLoopCount + 1
        sendSprite (me.spriteNum, #finishedLoop, pLoopCount)
      end if
      pSprRef.member = pMemberList[pCurrentMember]
    end if
  end if

end

This handler first checks a Boolean variable called pPlaying to see whether or not the animation should play at all. If pPlaying is false, then the animation will appear paused as your movie plays. If pPlaying is true, then the handler increments your frame counter. Next, the handler checks the frame counter against another variable called pFrameSpeed. The pFrameSpeed variable tells Director how many frames must elapse before the film loop is advanced to the next item. If you set pFrameSpeed equal to 1, then the animation will play fast because the loop changes images every frame. But if pFrameSpeed were set to 60, then the animation would be much slower because 60 frames in the score would need to elapse before the loop would move on to the next image.

If your current frame count is greater than pFrameSpeed, it means that you should display the next image in the list. First, you reset your frame counter, then increment the member counter (pCurrentMember). If the member counter is greater than the number of members in your list, then that means your film loop has finished and should start again from the beginning. So the code resets the loop to the beginning of the list and increments your loop counter. Finally it sends message called finishedLoop to the behaviors attached to the film loop sprite. This way, you can attach another behavior to the sprite that checks for these messages and executes specific code based on them. For instance, if you wanted a loop to run three times before going on to the next marker in your movie, you could add this code to another behavior on the same sprite.

on finishedLoop me, loopCount

  if loopCount >= 3 then
    go next
  end if

end

A sample Director 7 movie is available for download in Mac or Windows format.

Will Turnage is a multimedia programmer based in New York City. In addition to his weekly role as Director Online's Multimedia Handyman, he is also the Technology Director for Sony Music's Client Side Technologies Group. You can read more about his work at http://will.turnage.com/.

Copyright 1997-2024, Director Online. Article content copyright by respective authors.