double buffering - Allegro, sprites leaving trail -
i'm getting problem sprites leave trail behind when move them. tried drawning bg every refresh start flickering.
this do
// ... int main(int argc, char *argv[]) { bitmap *buffer = null; bitmap *graphics = null; buffer = create_bitmap(screen_w, screen_h); graphics = load_bitmap("my_graphics.bmp", null); clear_to_color(screen, makecol(0, 0, 0)); clear_to_color(buffer, makecol(0, 0, 0)); while(!key[key_esc]) { // ... render_map(100,100); // ... } } void render_map(int w, int h) { // ... for(int i=0;i < w * h;i++) { masked_blit(graphics, buffer, 0, 0, pos_x, pos_y, 32, 32); } // ... blit(buffer, screen, camera_x,camera_y,0,0,screen_w, screen_h); clear_to_color(buffer, makecol(0, 0, 0)); } thanks in advance help
your code little hard read, , you've left out big pieces of it. it's hard sure, line looks suspicious:
blit(buffer, screen, camera_x,camera_y,0,0,screen_w, screen_h); when using buffer, typically calling like:
blit(buffer, screen, 0,0, 0,0, screen_w,screen_h); and only time ever draw screen. steps are:
- clear buffer (by drawing background image, tileset, color, etc)
- draw buffer
- copy buffer screen
- repeat
Comments
Post a Comment