Game Development Reference
In-Depth Information
With the basic structure of the script done, we sill have to igure out where to place the
ileGenerator sprite before we stamp an image. This requires some calculaions based on the
number of repeats the loops are currently at. To save these values, we use the xIndex and
yIndex variables as counters. Perform the following steps:
1. First, we can assume that ileSize * xIndex shifts the sprite right across the width of
the stage without leaving gaps between stamps. The ileSize * yIndex formula shifts
the sprite up across the height of the stage.
2. However, 0 * 60 = 0 would be the center of the stage. We don't want to start at the
center. We need to start at the lower-let corner. So we have to adjust the staring
value. We need to subtract half the stage width or height from the coordinate value.
So, the formulas will become ileSize * xIndex - 240 and ileSize * yIndex - 180
3. Complete the formula and test this. The iles will be placed nicely beside each other;
but when the drawing completes, we sill see a problem. The enire map is ofset to
the lower left and a wide blank strip is showing along the top and right-hand side of
the stage.
4. This offset is caused because the center point of the sprite is placed in the middle
of it, and this is the point that gets aligned to the coordinates in the calculaion. So
we have to add an ofset for half the width or height of the ile to shit all the iles
towards the upper right a bit. The complete formulas will be as follows:
ileSize * xIndex - 240 - ileSize / 2
ileSize * yIndex - 180 - ileSize / 2
The following screenshot shows the formulae:
This fixes our offset problem. The maze is now correctly aligned with the stage boundaries.
Search WWH ::

Custom Search