Appendix C: Using the BMPStitch Utility - Learn VB .NET Through Game Programming [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Learn VB .NET Through Game Programming [Electronic resources] - نسخه متنی

Matthew Tagliaferri

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید





Appendix C: Using the BMPStitch Utility

Using POV-RAY to Create animated bitmaps (described in the previous appendix) introduces a minor issue: the need to convert many individual frame bitmaps into a single multicell bitmap. This isn’t a required step for creating the games in this book, but it’s much easier to manage one large bitmap (in code and in Visual Studio) than it is to manage 36 smaller bitmaps. Figures C-1 and C-2 show the task needed.


Figure C-1. Turning these individual bitmaps …



Figure C-2. …into a single bitmap

Smashing the 36 smaller images into one big one is nothing more than a cut-and-paste job. With a little patience and the Paint utility that comes with any version of Windows, you could, in time, create a large blank bitmap and copy each little bitmap into an appropriate place. This sounds a bit too much like real work, though—lining up images to single-pixel accuracy, dozens of copy-and-paste tasks—you can probably think of much better things you’d like to do with you time. It’d be much simpler if you had a program that could take the 36 images as input and smash them together for you.


Using BMPStitch


The BMPStitch utility is the solution to getting out of the tedious cut-and-paste job just described. In addition, this little utility lets you clip the individual bitmaps down, removing unneeded border space in each frame. This utility is useful enough that I’ve included it with the source code that accompanies this book so that you might be able to use it in your projects, should you find the need.

The program is a single-form solution that displays one of the images you intend to paste together. Clicking the Open button opens a standard dialog box so that you can select the first image in the intended animation sequence. Once selected, it displays on the form, as shown in Figure C-3.


Figure C-3. Interface of the BMPStitch utility

The utility assumes you want to stitch together all of the image files found in the same folder as the first image you selected with the Open button. Thus, the best way to organize your art directories is such that all of the individual cells for a given animated bitmap reside in a folder by themselves.

The preview picture box in the utility contains two horizontal and two vertical lines that can be arranged on the bitmap. These lines serve as a clipping area within each bitmap. The text at the bottom of the form shows the clipping rectangle that will be used based on the orientation of the clipping lines. (Knowing the rectangle height and width of each cell is useful in the game program that’s going to use the final bitmap in an animated sequence because this is the same height/width that will be needed to display one of the cells.)

You can preview the animated sequence by clicking the Anim button. This loads each bitmap found in the folder into the picture box. This feature is useful for making sure your clipping rectangle doesn’t cut off any of the image as it moves.


Once you’ve loaded a bitmap, adjusted the clipping region, and made sure it all looks the way you want it, you build the final bitmap by choosing the number of rows and columns to create using the across/down selectors and then clicking the Build button. The utility then performs the tedious copy/paste job and saves the final bitmap as c:\BMPStitch.bmp.





Note

I didn’t want to save the final bitmap into the same folder as the cell bitmaps because then the utility, if run a second time, would use this bitmap as one of the cells, which would in turn produce undesired results. This could be fixed if the cell-reading code were perhaps “smarter” and chose only those bitmaps with the same height and width as the first selected bitmap or perhaps those with a name similar to the first selected bitmap, but this is a quickie in-house utility, so perfection isn’t necessary. It saved enough cut-and-paste work for me that I didn’t mind taking the final file, renaming it, and putting it into the Visual Basic .NET project folder.


/ 106