Turret Control


Turret Control

For the control's indicator lines to rotate programmatically, one end of the line inside the indicator movie clip had to be placed at its internal center point. (See Figure 25.3.)

Figure 25.3. Notice that the beginning of the indicator is at the center point of the movie clip that it is contained within.

graphics/25fig03.gif

Inside one of the three control symbols, I placed the following code on the arrow button that was pointing up:

 on (press) {     uppressed = true;  }  on (release, releaseOutside) {     uppressed = false;  } 

This caused the new uppressed variable to become true when the player clicked the button, and false when he let go of it. I copied this code and pasted it on the arrow button instance that pointed down, replacing the uppressed variable with a new downpressed variable. I embedded the up arrow button pointing up into a new movie clip symbol named uparrow, and I embedded the button pointing down into a new movie clip named downarrow. Then in the other two controls, I replaced the two arrow button instances with the uparrow and downarrow movie clips to make the controls respond to the uppressed and downpressed variables .

Direction Control

The direction control (see Figure 25.4) allows players to point their tank's turret in a particular direction. Because the tanks aren't allowed to cross to the other player's island, the indicator's range is 180 °, from the top to the bottom of the screen.

Figure 25.4. The direction control allows players to point their turret in the range of “90 ° to 90 °.

graphics/25fig04.gif

The center of the indicator (the end of the line) is at the center of the half-circle. I replaced the arrow button instance pointing up with the new uparrow movie clip and placed the following code onto it:

 onClipEvent (enterFrame) {     if (uppressed) {         if (_root.indicator._rotation<90) {             ++_root.indicator._rotation;      }  } 

The onClipEvent(enterFrame) event is triggered continuously. When the button inside the movie clip sets uppressed to true, the second if statement checks to see if the rotation property is less than 90. If it is, the indicator isn't pointing straight up, so the rotation property of the indicator is incremented by 1 °, turning it counter-clockwise.

Then I replaced the arrow button instance that pointed down with the new movie clip called downarrow, and I copied the code from the uparrow movie clip onto it. I changed the increment operator ( ++ ) to a decrement ( - ) operator, and I changed the if statement so that it decremented the _rotation property of the indicator only when the value was greater than “90, to make sure that it wasn't pointing straight down yet.

The direction control was fully functional at this point. The onClipEvent(enterFrame) events updated the rotation property of the indicator movie clip repeatedly while either of the two arrow buttons was being pressed.

Angle Control

The angle control (see Figure 25.5) allows players to angle the tank's turret so that the bomb will go higher or lower. The range of possible settings is 90 °, from perfectly horizontal to perfectly vertical.

Figure 25.5. The angle control allows players to angle the turret in the range of 10 ° to 90 °.

graphics/25fig05.gif

I copied the uparrow and downarrow movie clip instances from the direction control and replaced the two arrow instances with them. The only other change I had to make was on the downarrow movie clip. The if statement that checked the _rotation of the indicator needed to decrement that value if it was greater than 0.

Power Control

The power control (see Figure 25.6) allows players to set the thrust of the cannon blast. As with the angle control, I copied the uparrow and downarrow movie clips from the direction control and replaced the two arrow instances with them. Because the range is the same as with the direction control, no changes were necessary.

Figure 25.6. The power control was actually the same as the direction control during the storyboarding.

graphics/25fig06.gif



Inside Flash
Inside Flash MX (2nd Edition) (Inside (New Riders))
ISBN: 0735712549
EAN: 2147483647
Year: 2005
Pages: 257
Authors: Jody Keating

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net