( Index )

Brief Information about the Feb '04 CSIG Meeting

Bitmap Transparent Animation

B. Arnold

Animation About Info

Welcome to the CSIG, a Special Interest Group of the ACGNJ. The subject for this month is a continuing journey into C++ Graphical Windows programming.

Bitmap Animation is simply the process of taking two dimensional drawings and pictures and presenting them on the screen using techniques that make them move. Common applications include GAMES and INSTRUMENTS. This has always been possible on computers from the earliest times and with all operating systems. It is particularly attractive in the more recent operating systems (Win98, 2k, XP) because the screens are high resolution and have many, many colors (16 bit, 32 bit). A new graphics function (TransparentBlt) has been added which makes this process even easier to code.

Johannes Wallroth has a web site in Germany, www.programming.de, which is devoted to programming including C++. He presents a number of programs written in Borland C++ Builder. I have taken his code for Bitmap Animation and converted it into Microsoft Visual C++ 6.0 for this months topic.

Sample Code

void CScratchPad::DoRecalcAnimation()   // update memory image
  CDC memDC, srcDC; CBitmap *pOld1, *pOld2;   static int loop = 0;

  // Source image for background
    pOld1 = srcDC.SelectObject(&bgBMP); // SELECT IN
        pOld2 = memDC.SelectObject(&memBMP);// SELECT IN
          // Build memory image here
          memDC.BitBlt( 0, 0, ClientWidth, ClientHeight, &srcDC, 0, 0, SRCCOPY );

          // ===================================
          static int x1=50; x1+=3;
          if(x1>ClientWidth)  x1=-150;
          DoDrawTransparent(x1, 120, &vehicleBMP[0], &memDC, &srcDC);

          static int x2=250;  x2++;
          if(x2>ClientWidth)  x2=-150;
          DoDrawTransparent(x2, 200, &vehicleBMP[1], &memDC, &srcDC);

          static int x3=350;  x3--;
          if(x3<-50)      x3=ClientWidth;
          DoDrawTransparent(x3, 150, &vehicleBMP[2], &memDC, &srcDC);

          static int x4=150;  x4--;
          if(x4<-100) x4=ClientWidth;
          DoDrawTransparent(x4, 10, &vehicleBMP[3], &memDC, &srcDC);

          static int x5=220;  x5+=2;
          if(x5>ClientWidth)  x5=-250;
          DoDrawTransparent(x5, 30, &vehicleBMP[4], &memDC, &srcDC);
          // ===================================

        // Clean up here
        memDC.SelectObject(pOld2);      // SELECT OUT
    srcDC.SelectObject(pOld1);      // SELECT OUT

"Random Access" questions start at 7:30 Tuesday night.


Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page