Game Development Reference
In-Depth Information
ahoaeb$^]_gcnkqj`*u'^]_gcnkqj`D]hbDaecdp8op]ca*op]caDaecdp%
w
^]_gcnkqj`*u9op]ca*op]caDaecdp)^]_gcnkqj`D]hbDaecdp7
y
y
2. Save the I]ej[?d]n]_pan*]o file and test the project. Press the arrow keys and watch your
lh]uan character explore Phobos!
All you did is reverse a bit of the logic you were using to move the lh]uan object. When you press
the arrow keys, they move the ^]_gcnkqj` object in the direction opposite to the one you want the
lh]uan to move in. That's why you should add a minus sign to the rt and ru variables with these two
lines:
^]_gcnkqj`*t'9)rt7
^]_gcnkqj`*u'9)ru7
This creates the illusion that the lh]uan object is moving, when it's actually the ^]_gcnkqj` object
that's moving in the opposite direction. Oh, the wily ways of the video game programmer!
The conditional statements stop the ^]_gcnkqj` object from moving when its edges reach the stage
edges:
eb$^]_gcnkqj`*t'^]_gcnkqj`D]hbSe`pd8op]ca*op]caSe`pd%
w
^]_gcnkqj`*t9op]ca*op]caSe`pd)^]_gcnkqj`D]hbSe`pd7
y
ahoaeb$^]_gcnkqj`*t)^]_gcnkqj`D]hbSe`pd:,%
w
^]_gcnkqj`*t9,'^]_gcnkqj`D]hbSe`pd7
y
eb$^]_gcnkqj`*uÌ^]_gcnkqj`D]hbDaecdp:,%
w
^]_gcnkqj`*u9,'^]_gcnkqj`D]hbDaecdp7
y
ahoaeb$^]_gcnkqj`*u'^]_gcnkqj`D]hbDaecdp8op]ca*op]caDaecdp%
w
^]_gcnkqj`*u9op]ca*op]caDaecdp)^]_gcnkqj`D]hbDaecdp7
y
I'll leave the mental gymnastics up to you to figure out why it works the way it does, but it's simply one
more permutation of exactly the same logic that you used to stop the lh]uan at the stage edges.
Better scrolling
This simple scrolling system can actually take you quite far, but there are a few problems that some
fine-tuning can help solve:
When the scrollable area reaches its limit, the lh]uan object is prevented from moving all the
way to the stage's edge. Try holding down the right arrow key and see how far you get. At some
 
Search Nedrilad ::




Custom Search