Scrolling Example

One of the additional examples provided on the CD-ROM with this chapter is a research project in bitmap-based side scrolling. This technique is not new, of course—side-scrolling games have been around for decades. But it will be a new feature in the engine in due time. Bitmap scrolling layers along with tiled scrolling layers will make possible some interesting new games, such as classic Mario-style side scrollers with both bitmap and tiled layers rendered with parallax perspective and alpha blending. Now I know what a film director goes through during the final editing process. I would love to put the book on hold another month to fully develop this subject! Alas, it will have to be continued online.

Figure 13.1 shows a prototype bitmap scroller class that provides the ability to add multiple independently scrolling layers with alpha. In this example, two layers are being drawn transparently over a starry background. Work will continue on this example.

Figure 13.1. This example demonstrates layered side scrolling with transparency.


The second screenshot, Figure 13.2, shows a working example of bitmap scrolling in a small viewport on the screen. The texture was generated by a program called TextureGenerator, which is based on the Perlin random noise library and is provided in the sourcesonus folder of the CD. We used this code to generate real-time random planet textures in Starflight. The result: Every planet has a unique textured surface that need not be stored in a bitmap file, and the planet surface tiled scroller engine uses the texture for the tilemap! I’ve used the same texture generator to produce a molten planet texture for use as an example layer in this program.

Figure 13.2. This example shows the algorithm that makes side scrolling work.


Bitmap-based side scrolling is just the beginning of this future engine upgrade, which will include scrolling in any direction and support for tiled layers. I have covered these subjects in other books such as Beginning Game Programming, 2nd Edition (the prequel to this book in many ways) and Game Programming All In One, 3rd Edition, so the existing theory and example code will make it very easy to add this old but fun technique to the Advanced2D engine. Here’s an intriguing challenge: How would you integrate a scrolling layer system into the core engine so that layers are automatically updated and rendered, while maintaining mesh and sprite rendering at the same time?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset