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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

50 Pitch.Red2.targetx = -96;<br />

51 Pitch.Red2.targety = 120;<br />

52 Pitch.Red3.targetx = -151;<br />

53 Pitch.Red3.targety = -83;<br />

54 Pitch.Red4.targetx = 192;<br />

55<br />

56 }<br />

Pitch.Red4.targety = 0;<br />

Listing 18.4<br />

Chapter 18: Sports simulations<br />

The main game loop<br />

The main game loop is in the clip event for the ‘Pitch’ movie clip. Step one is <strong>to</strong> update the<br />

timer. The purpose of s<strong>to</strong>ring the ‘startTime’ is so that it can be used <strong>to</strong> calculate the elapsed time<br />

using<br />

secs = int((getTimer() - startTime)/1000);<br />

The ‘getTimer’ returns the system time in milliseconds; by subtracting the start time and dividing<br />

by 1000, the elapsed seconds can easily be calculated. This can then be stripped in<strong>to</strong> minutes and<br />

seconds using the integer value after division by 60 and the remainder after division by 60, the<br />

modulus opera<strong>to</strong>r ‘%’. The values for these two numbers are then converted in strings of two<br />

characters and built in<strong>to</strong> a string <strong>to</strong> display the time.<br />

1 function SetTimeStr(){<br />

2 secs = int((getTimer() - startTime)/1000);<br />

3 mins = int(secs/60);<br />

4 secs %= 60;<br />

5<br />

6 secstr = String(secs);<br />

7<br />

8 while (length(secstr)

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

Saved successfully!

Ooh no, something went wrong!