Game Development Reference
In-Depth Information
2. Save the I]ej[?d]n]_pan[Psk*]o file and test the project.
3. Use the arrow keys to move the lh]uan to the edges of the stage. The lh]uan will stop moving
when its center point reaches the edge, as shown in Figure 6-8.
Figure 6-8. The player object stops moving when it
reaches the edge of the stage.
The leftmost side and very top of the stage are always represented by a value of ,. To find out what
the values of the rightmost side and bottom of the stage are, use the op]ca*op]caSe`pd and op]ca*
op]caDaecdp properties. By default, Flash's stage dimensions are 550 by 400 pixels, which is what
you're using in this project. That means that the op]ca*op]caSe`pd property has a value of 11,, and
the op]ca*op]caDaecdp property has a value of 0,,.
You can actually change the dimensions of the stage at any time if you decide that you want to make the
game screen bigger or smaller. One advantage of using the op]ca*op]caSe`pd and op]ca*op]caDaecdp
properties is that if you change the stage dimensions, you don't have to tediously update the code by
hand with the new sizes. Using op]ca*op]caSe`pd and op]ca*op]caDaecdp means that they'll update
automatically. But no matter the size of the stage, the top and left size of the stage will always be 0, so
they remain the same.
The eb+ahoa statements work by checking to see whether the lh]uan object's t or u positions go
beyond the values that you defined as the edges of the stage. If they do, the lh]uan object is forced
back to that position, which is the very edge. Even though the lh]uan object does actually move
slightly beyond the stage boundaries that you set, you don't ever see it do that; you see it only at the
point at which it's been forced back. This is exactly the same situation as in Chapter 4, when you were
controlling the storybook cat's u position with buttons. Same problem; same solution. Remember, I
told you it would come back to haunt you at some point! But this time you're completely prepared.
Problem solved!
Let's have a quick look at the first conditional statement:
eb$lh]uan*t:op]ca*op]caSe`pd%
w
lh]uan*t9op]ca*op]caSe`pd7
y
 
Search Nedrilad ::




Custom Search