Game Development Reference
In-Depth Information
++Opkl^]_gcnkqj`]pop]caa`cao
eb$^]_gcnkqj`*t'^]_gcnkqj`D]hbSe`pd8op]ca*op]caSe`pd%
w
^]_gcnkqj`*t9op]ca*op]caSe`pd)^]_gcnkqj`D]hbSe`pd7
necdpEjjan>kqj`]nu9op]ca*op]caSe`pd7
y
ahoaeb$^]_gcnkqj`*t)^]_gcnkqj`D]hbSe`pd:,%
w
^]_gcnkqj`*t9,'^]_gcnkqj`D]hbSe`pd7
habpEjjan>kqj`]nu9,7
y
eb$^]_gcnkqj`*u)^]_gcnkqj`D]hbDaecdp:,%
w
^]_gcnkqj`*u9,'^]_gcnkqj`D]hbDaecdp7
pklEjjan>kqj`]nu9,7
y
ahoaeb$^]_gcnkqj`*u'^]_gcnkqj`D]hbDaecdp8op]ca*op]caDaecdp%
w
^]_gcnkqj`*u9op]ca*op]caDaecdp)^]_gcnkqj`D]hbDaecdp7
^kppkiEjjan>kqj`]nu9op]ca*op]caDaecdp7
y
y
2. Save the I]ej[?d]n]_pan*]o file and test the project. The lh]uan object can now explore the
entire area, right up to the stage edges.
This code works by extending the inner boundaries to the stage edges when the ^]_gcnkqj` object
has reached the limit of its movement. Let's look at how this works with the first eb statement in the
code (the new code is highlighted in bold):
eb$^]_gcnkqj`*t'^]_gcnkqj`D]hbSe`pd8op]ca*op]caSe`pd%
w
^]_gcnkqj`*t9op]ca*op]caSe`pd)^]_gcnkqj`D]hbSe`pd7
necdpEjjan>kqj`]nu9op]ca*op]caSe`pd7
y
If you press the right arrow, the ^]_gcnkqj` object moves until the conditional statement detects that
it has reached its limit. When that happens, it stops the ^]_gcnkqj` object from moving and then
gives the necdpEjjan>kqj`]nu variable a new value that is equivalent to the maximum width of the
stage. That allows the lh]uan object to move all the way to the stage edge. Figure 6-17 illustrates how
this works.
Problem solved! But you just created another one. How can you move the boundary back to its origi-
nal position if the lh]uan moves back to the center of the stage?
Think about it this way. Imagine that the lh]uan object has traveled to the rightmost edge of the stage,
as shown in Figure 6-17. When it travels back to the center of the stage, you don't have to start mov-
ing the ^]_gcnkqj` object again until the lh]uan object has reached the inner-left boundary. If it does,
you know that you can safely reset the inner-right boundary to its original position. That's what this
new line of code in bold does:
 
Search Nedrilad ::




Custom Search