Game Development Reference
In-Depth Information
lh]uan*t9op]ca*op]caSe`pd)lh]uanD]hbSe`pd7
y
ahoaeb$lh]uan*t)lh]uanD]hbSe`pd8,%
w
lh]uan*t9,'lh]uanD]hbSe`pd7
y
eb$lh]uan*u)lh]uanD]hbDaecdp8,%
w
lh]uan*u9,'lh]uanD]hbDaecdp7
y
ahoaeb$lh]uan*u'lh]uanD]hbDaecdp:op]ca*op]caDaecdp%
w
lh]uan*u9op]ca*op]caDaecdp)lh]uanD]hbDaecdp7
y
y
2. Save the I]ej[?d]n]_pan[Psk*]o file and test the project. You can now move the lh]uan
object to the edges of the stage, and the entire object will be contained inside it. Figure 6-9
shows an example.
Figure 6-9. The entire player object is contained
within the stage by adding half its height and width
to the calculation.
The first thing is to declare and initialize the two new local variables :
r]nlh]uanD]hbSe`pd6qejp9lh]uan*se`pd+.7
r]nlh]uanD]hbDaecdp6qejp9lh]uan*daecdp+.7
These variables store a value representing half of the lh]uan object's width and height. You know that
the lh]uan object is 50 pixels wide and 50 pixels high, so half that width and height is 25 and 25.
These variables are declared directly inside the kjAjpanBn]ia event handler. That's why they're
referred to as local . They can be used only inside this event handler and nowhere else. If you try using
 
Search Nedrilad ::




Custom Search