Game Development Reference
In-Depth Information
++>kppki
eb$u)daecdp+.:[op]caDaecdp%
w
l]najp*naikra?deh`$pdeo%7
y
++Habp
eb$t'se`pd+.8,%
w
l]najp*naikra?deh`$pdeo%7
y
++Necdp
eb$t)se`pd+.:[op]caSe`pd%
w
l]najp*naikra?deh`$pdeo%7
y
y
y
y
Let's take a closer look at the constructor method:
lq^he_bqj_pekj>qhhap[Bkqn@ena_pekjo$sa]lkj@ena_pekj6Opnejc%
w
[`ena_pekj9sa]lkj@ena_pekj7
]``ArajpHeopajan$Arajp*=@@A@[PK[OP=CA(kj=``a`PkOp]ca%7
y
Its parameter is called sa]lkj@ena_pekj* When the bullet is created, sa]lkj@ena_pekj contains exactly
the same value of the [`ena_pekj variable that was passed to it by the weapon. It has a value of ql,
`ksj, habp, or necdp. (The weapon's [`ena_pekj variable was a string, so sa]lkj@ena_pekj
needs to be typed as Opnejc as well.)
Any parameters that are used in the constructor method are local to the constructor method , so the
sa]lkjo@ena_pekj variable can't be used anywhere else in the class. The first job is to copy its value
over into a variable that can be used in the entire class. The >qhhap[Bkqn@ena_pekjo class has its
own property called [`ena_pekj that is used to store this information. When new bullet instances
are created, they use this new [`ena_pekj property to figure out in which direction they should be
traveling.
Now that bullet objects know the direction they have to travel, their velocity is simply assigned using
the [`ena_pekj property.
Accessing the stage outside of the document class
There's an extremely important oddity that you might have noticed in the >qhhap[Bkqn@ena_pekjo
class: these two lines of code in the kj=``a`PkOp]ca event handler:
[op]caSe`pd9op]ca*op]caSe`pd7
[op]caDaecdp9op]ca*op]caDaecdp7
 
Search Nedrilad ::




Custom Search