02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 18: Sports simulations<br />

37 if (frame>_root.ROTATIONFRAMES){<br />

38 frame -= _root.ROTATIONFRAMES;<br />

39 }<br />

40 eval(name).setFrame(frame);<br />

41 }else{<br />

42 rotateright = 1;<br />

43<br />

44<br />

}<br />

45 if (Key.isDown(Key.SPACE)){<br />

46 //Space Bar<br />

47 if (eval(name).balldist100){<br />

59 movecount = _root.PANFRAMES;<br />

60 }else{<br />

61 movecount = 0;<br />

62 }<br />

63 }<br />

64<br />

65 }<br />

}<br />

Listing 18.8<br />

The ‘setFrame’ function determines whether the player is actually already on the best frame <strong>to</strong><br />

display the current angle, because in this example we only have 32 different display angles but the<br />

clip can be set <strong>to</strong> any angle. We only need <strong>to</strong> update the frame when we move in<strong>to</strong> a new angle<br />

display. By finding the integer of the current frame after division by the step value and comparing<br />

this with the requested frame divided in the same way, we can see whether we have stepped in<strong>to</strong><br />

a new display block. Then we test for the current speed and set the player’s display frame <strong>to</strong> either<br />

a stationary rotate frame or a running display frame.<br />

1 function setFrame(frame){<br />

2 a = int(_currentframe/_root.PLAYERROTATESTEP);<br />

3 b = int(frame/_root.PLAYERROTATESTEP);<br />

4 if (a!=b){<br />

5 //Need <strong>to</strong> rotate our player<br />

6 b++;<br />

293

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!