Delete image for background

Hi,
for my work I use a black image as background, because if I don’t use
it,the foreground images overlap, generating a trail effect.
How can I don’t use the background image?
tnx

You can do one of two things, really:

  1. At the beginning of each frame, erase the entire screen,
    then draw all of your objects, then do an SDL_Flip() or _UpdateRect().
    Sounds like you’d rather not do this. :^) It definitely can be slow!

  2. At the beginning of each frame, erase each of the objects
    (just like drawing them all, except you’re drawing black).
    THEN, move the objects.
    Now, draw them in their new positions, and then update the screen
    (e.g., SDL_Flip())

Typically, I have SO much stuff moving on my screens (see: Defendguin)
that it’s cheaper/easier for me to just wipe the screen each frame.
Sometimes, though (see: Mad Bomber), it makes more sense to erase and
redraw just the few moving objects, rather than redraw /everything/…

-bill!On Thu, May 13, 2004 at 11:46:50PM +0200, NighTiger wrote:

Hi,
for my work I use a black image as background, because if I don’t use
it,the foreground images overlap, generating a trail effect.
How can I don’t use the background image?

  1. At the beginning of each frame, erase each of the objects
    (just like drawing them all, except you’re drawing black).
    THEN, move the objects.
    Now, draw them in their new positions, and then update the screen
    (e.g., SDL_Flip())

How I erase each of the objects?
Must I use SDL_FreeSurface? -:

Typically, I have SO much stuff moving on my screens (see: Defendguin)
that it’s cheaper/easier for me to just wipe the screen each frame.
Sometimes, though (see: Mad Bomber), it makes more sense to erase and
redraw just the few moving objects, rather than redraw /everything/…

tnx for your explanationIl gio, 2004-05-13 alle 23:52, Bill Kendrick ha scritto:

Nah! :^) That would simply get rid of the image from memory, so you
couldn’t blit it again later!

I mean simply draw a black rectangle in the location where the ‘sprite’ was.

e.g.

/* Erase all objects: */

/* Cheap but slow way is:
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); */

for (i = 0; i < NUM_OBJECTS; i++)
{
SDL_Rect dest;

dest.x = objects[i].x;
dest.y = objects[i].y;
dest.w = monster->w;        /* say "monster" is the SDL_Surface * of the */
dest.h = monster->h;        /* object you want to erase 

SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format, 0, 0, 0));

}

/* Move the objects: */

for (i = 0; i < NUM_OBJECTS; i++)
{
/* … do something with objects[i].x and .y … */
}

/* Draw the objects: */

for (i = 0; i < NUM_OBJECTS; i++)
{
SDL_Rect dest;

dest.x = objects[i].x;
dest.y = objects[i].y;

SDL_BlitSurface(monster, NULL, screen, &dest);

}

/* Update the screen: */

/* Better way would probably be to keep an array of SDL_Rects
covering the precise areas we changed, and then sent it to
SDL_UpdateRects() */

SDL_Flip(screen);

All done!

-bill!On Fri, May 14, 2004 at 08:55:39AM +0200, NighTiger wrote:

Il gio, 2004-05-13 alle 23:52, Bill Kendrick ha scritto:

  1. At the beginning of each frame, erase each of the objects
    (just like drawing them all, except you’re drawing black).
    THEN, move the objects.
    Now, draw them in their new positions, and then update the screen
    (e.g., SDL_Flip())

How I erase each of the objects?
Must I use SDL_FreeSurface? -: