Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help converting this function to basic
#1
Hi,

I've been playing around with allegro in freeBASIC and have found a highcolor fading function that works in C. I've tried a few times to get this converted to basic so I can use this in my allegro-freebasic program i'm attempting.

the C code is as follows
Code:
void highcolor_fade_out(int speed)
{
    BITMAP *bmp_orig, *bmp_buff;

    if ((bmp_orig = create_bitmap(SCREEN_W, SCREEN_H)))
    {
        if ((bmp_buff = create_bitmap(SCREEN_W, SCREEN_H)))
        {
            int a;
            blit(screen, bmp_orig, 0,0, 0,0, SCREEN_W, SCREEN_H);
            if (speed <= 0) speed = 16;
        
            for (a = 255-speed; a > 0; a-=speed)
            {
                clear(bmp_buff);
                set_trans_blender(0,0,0,a);
                draw_trans_sprite(bmp_buff, bmp_orig, 0, 0);
                vsync();
                blit(bmp_buff, screen, 0,0, 0,0, SCREEN_W, SCREEN_H);
            }
            destroy_bitmap(bmp_buff);
        }
        destroy_bitmap(bmp_orig);
    }

    rectfill(screen, 0,0, SCREEN_W,SCREEN_H, makecol(0,0,0));
}

If anyone knows if this can or cannot be done, please let me know. Any help is appreciated.

Thanks
o time for the old in-out Love, I've just come to check the meter.
Reply
#2
Here's a straight translation (untested) :
Code:
sub highcolor_fade_out(byval speed as integer)
    dim bmp_orig as BITMAP Ptr, bmp_buff As BITMAP Ptr
    dim a as integer

    bmp_orig = create_bitmap(SCREEN_W, SCREEN_H)
    if (bmp_orig <> 0) then
        bmp_buff = create_bitmap(SCREEN_W, SCREEN_H)
        if bmp_buff <> 0 then
            blit screen, bmp_orig, 0,0, 0,0, SCREEN_W, SCREEN_H
            if (speed <= 0) then speed = 16
      
            for a = 255-speed to 0 step -speed
                clear_bitmap bmp_buff
                set_trans_blender 0,0,0,a
                draw_trans_sprite bmp_buff, bmp_orig, 0, 0
                vsync
                blit bmp_buff, screen, 0,0, 0,0, SCREEN_W, SCREEN_H
            next a
            destroy_bitmap bmp_buff
        end if
        destroy_bitmap(bmp_orig);
    end if

    rectfill screen, 0,0, SCREEN_W,SCREEN_H, makecol(0,0,0)
end sub
Reply
#3
Nice job, it works perfectly. Got an error though, you missed a semi-colon. Smile

I have another one, for a fading-in effect, which I'll try myself but will post if I need any assistance.

Thanks!
o time for the old in-out Love, I've just come to check the meter.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)