Game Development Reference
In-Depth Information
The source of the copy is the instance of the Tilesheet class we created to hold our library tile
sheet. It's the 32
32 rectangle ( tileBlitRectangle ), and its location is the point ( blitPoint ) that
we set previously.
We do this operation for each tile in the level.
Optimization! A big optimization we put into practice here was using a single Point class instance
and a single Rectangle class instance. Creating objects is a very processor-intensive activity. By
using a single instance of each of these two, we took up a little extra memory up front but saved a
lot of processor in return. In the next chapter, we will be using these techniques to blit changes to
the display objects on each frame and this optimization will come in very handy.
The last thing you will notice is the canvasBitmapData.lock before the copyPixels operation and
the canvasBitmapData.unlock after the copyPixels operation. This optimization will help in screen
rendering. It allows the copyPixels operation to occur off screen. The lock tells all display objects
that have this BitmapData as an attribute reference to not update themselves until the unlock is
set. This will keep screen updates looking as smooth as possible.
This is the final code for the chapter. If you type it all in, with no errors, and test move, build with
Flash Develop/Flex, you will see the output shown in Figure 6-13.
Figure 6-13. The output in Flash Develop
Search WWH ::




Custom Search