I have a problem when moving a bitmap: There remains a trail where the
bitmap moved over. It looks like as if
the bitmap has been “smeared” over the screen.
I know that i have to save the background before drawing the bitmap,
then blit the image to the screen, update the part of the screen i
blitted the image to and finally restore the background.
I do all this in a loop. Here’s the source:
SDL_Surface * window; // the 640 * 480 main window
SDL_Surface * tmp;
SDL_Surface * bitmap; // the image i want to move
SDL_Rect rectangle; // the dimension / x and y Position of the bitmap
// this is the surface i save the background to. It’s initialisied once
at the beginning of my program
rectangle.y = 100; // set y Position of the bitmap to 100
rectangle.w = bitmap->w; // set width
rectangle.h = bitmap->h; // set height
for (int i=100;i<400;i++)// my drawing loop
rectangle.x += 1; // move the bitmap one pixel
forward by increasing its x Pos.
SDL_BlitSurface(window,&rectangle,tmp,NULL); // save the Background
to the tmp Surface
SDL_BlitSurface(bitmap,NULL,window,&rectangle); //now blit the
bitmap to the window
// update the concerned part "rectangle" of the window SDL_UpdateRect(window, rectangle.x ,rectangle.y, bitmap->w,
SDL_BlitSurface(tmp,NULL,window,&rectangle); // restore the background
I must do something wrong , but i really don’t know what it is. I’m
using SDL Version 1.2.2 on Linux and will be very, very happy if someone
could help me please !
Thanks in advance