Trying to change transparancy in sprite function

So I've been watching a tutorial for SDL. The guy separates the transparency function from the sprite placement function. I thought I would try putting the transparency function in with the sprite function. I am not, as yet, sure why it won't work this way. Although there are no compiler errors, the transparency comes out...opaque. This is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <SDL.h>

SDL_Surface *screen = NULL;
SDL_Surface *background = NULL;
SDL_Surface *sprite = NULL;

void Apply_Surface(int x, int y, SDL_Surface * source, SDL_Surface * destination)
{
    SDL_Rect rect;
    rect.x = x;
    rect.y = y;

    SDL_BlitSurface(source, NULL, destination, &rect);
}

void Draw_Sprite (int srcx, int srcy, int dstx, int dsty, int width, int height, SDL_Surface *source, SDL_Surface *destination)
{
/*==================================================================================*/
//This is where I put the tut creators transparancy function
    SDL_SetColorKey(source, SDL_SRCCOLORKEY, SDL_MapRGB(source->format, 255, 0, 255));

    SDL_Rect src;
    src.x = srcx;
    src.y = srcy;
    src.w = width;
    src.h = height;

    SDL_Rect dst;
    dst.x = dstx;
    dst.y = dsty;
    dst.w = width;
    dst.h = height;
}

int main ( int argc, char* argv[] )
{
    SDL_Init(SDL_INIT_EVERYTHING);
    screen = SDL_SetVideoMode(600, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    SDL_WM_SetCaption("YouTube Tut 01", NULL);
    background = SDL_LoadBMP("grid.bmp");
    sprite = SDL_LoadBMP("ship.bmp");
/*=====================================================================================*/
//This is where the tut creator, originally,  placed the transparency function.
    //SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, SDL_MapRGB(sprite->format, 255, 0, 255));

    bool running = true;

    while(running)
    {
        SDL_Event event;

        if(SDL_PollEvent(&event))
        {
            if(event.type == SDL_QUIT)
            {
                running = false;
            }
        }
        Apply_Surface(0,0, background, screen);
        Apply_Surface(240, 240, sprite, screen);
        SDL_Flip(screen);
    }
    SDL_Quit();

    return 0;
}

Note: I haven't included the variables in the header yet.

So I guesss I just need to know if I am misunderstanding the use of this function or if it has to be where the tut creators selected position in line 44? Thanks for taking the time to look at this. :o)

Edit: I forgot that I needed to change line 60 to this:
Draw_Sprite(0, 0, 0, 0, 80, 80, sprite, screen);

Apparently, my understanding of SDL is less incomplete than I had thought. I feel better now. But if someone has anything useful to say...I am still just starting. Both with SDL and more importantly with C++. Thanks.
Last edited on
Topic archived. No new replies allowed.