Game Development Reference
In-Depth Information
Blocking movement at the edge of the stage.
Screen wrapping. This is what happens when the lh]uan leaves the left side of the stage and
emerges from the right.
Scrolling. When the lh]uan object is in a very big environment, the background moves to
reveal unexplored areas.
You'll have a look at each of these techniques one at a time.
Blocking movement at the stage edges
Like most programming problems, if you understand the logic behind what you're trying to accom-
plish, all you need to do is figure out a way of representing that logic with programming code. Here's
the logic behind what is accomplished with this bit of code:
Ebpdalh]uank^fa_pna]_daopdaa`cakbpdao_naaj(lqodep^]_g*
Hmm. Easier said than done? Let's see.
AS3.0 doesn't have any way of representing “the edge of the screen” as a whole, but you can access the
built-in op]ca object. It contains op]caSe`pd and op]caDaecdp properties that tell you how big the stage is.
Maybe you can use those properties to figure out the top, bottom, left, and right boundaries of the stage
and then stop the lh]uan object from moving if you discover that its t or u positions go beyond them?
Sound promising? Give it a whirl! Follow these steps:
1. Add the following code to the kjAjpanBn]ia event handler:
bqj_pekjkjAjpanBn]ia$arajp6Arajp%6rke`
w
++Ikrapdalh]uan
lh]uan*t'9rt7
lh]uan*u'9ru7
++Opkllh]uan]pop]caa`cao
eb$lh]uan*t:op]ca*op]caSe`pd%
w
lh]uan*t9op]ca*op]caSe`pd7
y
ahoaeb$lh]uan*t8,%
w
lh]uan*t9,7
y
eb$lh]uan*u8,%
w
lh]uan*u9,7
y
ahoaeb$lh]uan*u:op]ca*op]caDaecdp%
w
lh]uan*u9op]ca*op]caDaecdp7
y
y
 
Search Nedrilad ::




Custom Search