Game Development Reference
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:
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: