Game Development Reference
In-Depth Information
The [peian object now triggers the kjQl`]paPeia event handler every second:
lner]pabqj_pekjkjQl`]paPeia$arajp6Arajp%6rke`
w
peia@eolh]u*patp9Opnejc$[peian*_qnnajp?kqjp%7
++Opklpeiansdajepna]_dao-,
eb$[peian*_qnnajp?kqjp99-,%
w
[peian*naoap$%7
[peian*op]np$%7
y
y
Peian objects have a property called _qnnajp?kqjp that tells you how many times the timer event has
fired since it started. The kjQl`]paPeia event copies the value of _qnnajp?kqjp to the peia@eolh]u
dynamic text field on the stage:
peia@eolh]u*patp9Opnejc$[peian*_qnnajp?kqjp%7
You can use _qnnajp?kqjp as done here: to display the number of times the event has been triggered.
The eb statement uses _qnnajp?kqjp to check whether ten seconds have elapsed; if they have, it calls
the Peian class's naoap and op]np methods:
[peian*naoap$%7
[peian*op]np$%7
naoap stops the timer and also resets _qnnajp?kqjp to zero. To start the timer again, you need to use
the op]np method once more. (If you need to stop the timer completely in any of your games, you can
use the opkl method. opkl stops the timer without resetting _qnnajp?kqjp.)
When you create a Peian object, you can add a second argument, which is known as nala]p?kqjp.
This is a number that tells the timer how many times it should repeat. You can see the effect of using
nala]p?kqjp by updating the directive that creates the [peian object so that it looks like this:
[peian9jasPeian$-,,,(1%7
If you test the project, you'll see that the numbers count up to five. After that, the event is no longer
called.
There are a few more Peian class properties that you should know about. If you need to change the
interval between events, you can use the `ah]u property. For example, if you want the timer event to
be triggered every one-half second, you can set the delay to 500 milliseconds, like this:
[peian*`ah]u91,,7
If you need to know whether a timer is currently running, you can use the nqjjejc property. nqjjejc
returns pnqa when the timer is running and b]hoa when it isn't.
 
Search Nedrilad ::




Custom Search