Pausing the Rotation

Right now, when you flip two cards over and don't make a match, they instantly flip back. It's so fast, you hardly have enough time to see what the second card was. In this section you'll add a simple timing mechanism to the game loop that will pause the rotation for half a second before the cards flip back.


Open your copy of the memory game from your project_four folder. Right-click the 3D sprite and select Script from the context menu. Add the following property declaration at the top of the script:

 property flipPause 


In the enterFrame handler, initialize flipPause within the same block of code that executes when a match is not made. This is the block of code that sets up the two transformobjects. You can add the code right after the line that sets transformPercent to 0:

 flipPause = _system.milliseconds + 500 

This sets flipPause to half a second later than the current time.


Add the following conditional test immediately after the line that checks if isRotating is equal to 2, and immediately before the two lines that interpolate the two cards:

 if _system.milliseconds > flipPause then 


Finally, add an end if statement to the end of the enterFrame handler, to close the timing test conditional statement.

For reference, the enterFrame handler should now look like this:

 on enterFrame me    if isRotating = 1 then    whichMod.transform = origTransform.interpolate(finalTransform, ¬     transformPercent)    transformPercent = transformPercent + 5    if transformPercent > 100 then     isRotating = 0     if flippedList.count() = 2 then      if _global.solveList[flippedList[1]] = ¬       _global.solveList[flippedList[2]] then       matchList.add(flippedList[1])       matchList.add(flippedList[2])       flippedList = []      else     isRotating = 2     whichMod = wrld.model("c" & string(flippedList[1]))     whichMod2 = wrld.model("c" & string(flippedList[2]))     origTransform = whichMod.transform.duplicate()     finalTransform = whichMod.transform.duplicate()     finalTransform.rotation.y = 180     origTransform2 = whichMod2.transform.duplicate()     finalTransform2 = whichMod2.transform.duplicate()     finalTransform2.rotation.y = 180     transformPercent = 0     flipPause = _system.milliseconds + 500    end if   end if  end if  end if if isRotating = 2 then   if _system.milliseconds > flipPause then    whichMod.transform = origTransform.interpolate(finalTransform, ¬     transformPercent)    whichMod2.transform = origTransform2.interpolate(finalTransform2, ¬     transformPercent)    transformPercent = transformPercent + 5    if transformPercent > 100 then     isRotating = 0     flippedList = []    end if   end if  end if end 


Rewind and play the movie.

When you flip over two cards that don't make a match, the cards now pause for half a second before flipping back.

With that out of the way, let's add a timer. This will act as a scoring device, by showing how fast you complete the game.

Macromedia Director MX 2004. Training from the Source
Macromedia Director MX 2004: Training from the Source
ISBN: 0321223659
EAN: 2147483647
Year: 2003
Pages: 166
Authors: Dave Mennenoh

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: