0

I've been having this problem for a while. When I compile this part of my code It shows black lines above the bitmaps. What might be the problem and are there any solutions?

void start()
{
    FONT *verdana;
    PALETTE palette;
    verdana = load_font("verdana.pcx", palette, NULL);
    clear_to_color(screen,makecol(0,0,0));
    SAMPLE *tac = load_sample("clunk.wav");

    topce_bmp=load_bitmap("topce.bmp",NULL);
    palki_bmp=load_bitmap("palka.bmp",NULL);

    int cred_anim=255;
    int cred_anim_fade=0;
    SPEED=4;
    int timer=0;      
    while(cred_anim_fade!=255)
    {
         line( screen, 3, 0, 3, 600, makecol( cred_anim_fade, cred_anim_fade, cred_anim_fade));
         line( screen, 797, 0, 797, 600, makecol( cred_anim_fade, cred_anim_fade, cred_anim_fade));
         if(key[KEY_ENTER])
         {
              menu(0,NULL);
         }

//      BATS


        if(y>0&&y<400)
        {
           y=posy-100;
        }
        else if(y<=0) y=1;
        else if(y>=400) y=399;

        draw_sprite( screen,palki_bmp, 20, y);

        if(y1>0&&y1<400)
        {
            y1=posy-100;
        }
        else if(y1<=0) y1=1;
        else if(y1>=400) y1=399;

        draw_sprite( screen,palki_bmp, 765, y1);
        rest(10);
        cred_anim_fade++;
    }

    while (timer!=1000)
    {

        if(key[KEY_ENTER])
         {
              menu(0,NULL);
         }

        timer++;
        acquire_screen();

        clear_to_color(screen,makecol(0,0,0));


//      BORDERS

         line( screen, 3, 0, 3, 600, makecol( 255, 255, 255));
         line( screen, 797, 0, 797, 600, makecol( 255, 255, 255));

//      BATS


        if(y>0&&y<400)
        {
           y=posy-100;
        }
        else if(y<=0) y=1;
        else if(y>=400) y=399;

        draw_sprite( screen,palki_bmp, 20, y);

        if(y1>0&&y1<400)
        {
            y1=posy-100;
        }
        else if(y1<=0) y1=1;
        else if(y1>=400) y1=399;

        draw_sprite( screen,palki_bmp, 765, y1);



//      COLLISION X-AXIS

        if(check_posy==1)
        {
            if(posy<15) 
            {
                posy=posy+SPEED;
                check_posy=1;
            }
            else if(posy>585) 
            {
                posy=posy-SPEED;
                check_posy=2;
            }
            else posy=posy+SPEED;
        }
        else if(check_posy==2)
        {
            if(posy<15) 
            {
                posy=posy+SPEED;
                check_posy=1;
            }
            else if(posx>585) 
            {
                posy=posy-SPEED;
                check_posy=2;
            }
            else posy=posy-SPEED;
        }


//       COLLISION WITH BATS

        if(check_posx==1)
        {
            if(posx<50&&posy>y&&posy<y+200) 
            {
                SPEED=SPEED+3;
                posx=posx+SPEED;
                check_posx=1;
                play_sample(tac,500, 100, 1000, 0);
            }
            else if(posx>750&&posy>y1&&posy<y1+200) 
            {
                SPEED=SPEED+3;
                posx=posx-SPEED;
                check_posx=2;
                play_sample(tac,500, 0, 1000, 0);
            }
            else posx=posx+SPEED;
        }
        else if(check_posx==2)
        {
            if(posx<50&&posy>y&&posy<y+200) 
            {
                SPEED=SPEED+3;
                posx=posx+SPEED;
                check_posx=1;
                play_sample(tac,500, 100, 1000, 0);
            }
            else if(posx>750&&posy>y1&&posy<y1+200) 
            {
                SPEED=SPEED+3;
                posx=posx-SPEED;
                check_posx=2;
                play_sample(tac,500, 0, 1000, 0);
            }
            else posx=posx-SPEED;
        }

        draw_sprite( screen,topce_bmp, posx-13, posy-10);

        rest(10);
    }
    clear_to_color(screen,makecol(0,0,0));
    textout_centre_ex(screen, verdana, "PONG!",400,320, makecol(cred_anim,0,0),makecol(0,0,0));
    textout_centre_ex(screen, verdana, "Vistinska igra.",400, 420, makecol(cred_anim,cred_anim,cred_anim),makecol(0,0,0));
    rest(3000);
    while(cred_anim!=0)
    {
        clear_to_color(screen,makecol(0,0,0));
        textout_centre_ex(screen, verdana, "PONG!",400,320, makecol(cred_anim,0,0),makecol(0,0,0));
        textout_centre_ex(screen, verdana, "Vistinska igra.",400, 420, makecol(cred_anim,cred_anim,cred_anim),makecol(0,0,0));
        cred_anim--;
        rest(1);
    }
}
Martin
  • 710
  • 2
  • 11
  • 18
  • Can you figure out a minimal subset of this code that produces the bug? For example, if you comment out everything but the rendering of one sprite in a fixed position, do you still have the problem? – user168715 Apr 30 '11 at 16:32
  • I think it has something to do with the clear_to_color() function in the while loop. If I comment out clear_to_color() from the while loop i doesn't show the lines but all bitmaps leave trace as they move so that's not a solution. – Martin Apr 30 '11 at 17:25

1 Answers1

1

Just a few ideas concerning the code:

-You call acquire_screen() but never call release_screen(). THIS IS BAD, not to mention all the warnings allegro gives you in the documentation for acquire_screen().

-"Black lines" is a bit vague (when, where, and to what extent do they appear?) but it might also be an issue with drawing directly to the screen, based on your comment about how clear_to_color() seems to cause the problem. Try double buffering, that can solve several issues.

Hope this helps. Even if these don't solve your problem they're good things to keep in mind.

Zilchonum
  • 681
  • 1
  • 5
  • 9
  • Yes I tried double buffering and it worked! Also i didn't copy the whole code so that's why release_screen() is missing, but in fact it is there. Thanks for the reply! – Martin Apr 30 '11 at 22:14