Game Programming Q&A



I was wondering if it is possible to double buffer shapes (not the shape component) drawn on a canvas in Builder. Would I have to draw all the shapes to a canvas and than draw this canvas to my form? 



Double buffering is done to minimize the screen flicker that occurs when writing to video memory. As such it is best to minimize the video memory access by only writing to the screen those areas that change from one frame to the next. In the tank game I create an offscreen canvas that is the same size as the visible screen. An image is drawn to the offscreen canvas and then the CopyRect( ) function is called to copy the rectangular area that has changed to the visible screen. It looks something like this:

// Perform dirty rectangle animation on memory and Form canvas

// draw explosion image

workCanvas->CopyMode = cmSrcCopy;

workCanvas->CopyRect(changeRect, imagesCanvas, imageOffset[explodeNum]);

// draw to visible screen

form->Canvas->CopyRect(changeRect, workCanvas, changeRect);


Another question I have about double buffering is what does the RealizePalette( ) during an OnPaint event do? I saw this in your tank game and the EarthPong game that comes with Builder's example programs and I am not sure what it does. Does it just refresh the graphics on each canvas? 



RealizePalette( ) function maps palette entries from the current logical palette to the system palette. What that means is, the color palette from the specified device context (DC) is mapped into the system palette. This simply keeps the colors the same in all of the DCs.