# (SDL) Setting Transparent Color Problem

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, Before now, I have never had to set a Transparent Color in SDL. I looked up what to do, so I could set a transparent color. I followed it's instructions, and well...my Program will not compile. I get two errors, and those are:
15 C:\Documents and Settings\Chad\Desktop\Distaster in 1415\main.cpp expected constructor, destructor, or type conversion before '(' token

15 C:\Documents and Settings\Chad\Desktop\Distaster in 1415\main.cpp expected ,' or ;' before '(' token


Those are the errors I get, and those errors all point to the Transparent Color Code. I look at it and the example, and it seems correct. I can't seem to figure out why though it gives me those errors. Here is the line of code that sets a Transparent Color:
SDL_SetColorKey(english, SDL_SRCCOLORKEY, SDL_MapRGB(english->format, 255, 0, 255));

That is correct isn't? That code is placed DIRECTLY under the SDL_Surface* english code. Why do I get those two errors? I can't seem to figure out why. I know it is that line of code, because I comment that out, and it compiles fine. I am sure it is easy to figure out again, and I am just stupid and am missing the easy mistake. It has been in my brain for 30 minutes though, and nothing! Chad.

##### Share on other sites
Can you post some of the surrounding code?

##### Share on other sites
That looks O.K. to me... If you're missing a ',' or ';' then most likely it's not from that function, even though it compiles without it. Give us 5 lines above and 5 lines under the color key. Are you using a class? Maybe you forgot the ';' on the end? Like so: class Foo { ... };. Good luck!

C++

##### Share on other sites
SDL_Surface* background=SDL_LoadBMP("gbackground.bmp");SDL_Surface* ship=SDL_LoadBMP("ship.bmp");SDL_Surface* english=SDL_LoadBMP("english.bmp");SDL_SetColorKey(english, SDL_SRCCOLORKEY, SDL_MapRGB(english->format, 255, 0, 255));SDL_Surface* english2=SDL_LoadBMP("arrow.bmp");SDL_Rect ship_source;SDL_Rect ship_dest;SDL_Rect english_source;

There y'all go. I'm working on other stuff right now, so I don't fall behind on stuff.

##### Share on other sites
Well, that's odd. I don't see anything wrong..?
Do you use any classes? Maybe you forgot one semicolon on the end of a class:

class Foo // a class
{
public:
private:
protected:
}; // have a semicolon here

Good luck.

C++

##### Share on other sites
Where exactly is that code? Is it IN a function or OUT? If it's not in a function, then it will not work correctly. Furthermore, if it's not in a function, there will be a lot of other runtime errors that will result if that code is executed. Since SDL_SetColorKey is a function call, it cannot reside in the global scope. If that's not the problem, then HMMM.

##### Share on other sites
Quote:
 Original post by Drew_BentonWhere exactly is that code? Is it IN a function or OUT? If it's not in a function, then it will not work correctly. Furthermore, if it's not in a function, there will be a lot of other runtime errors that will result if that code is executed. Since SDL_SetColorKey is a function call, it cannot reside in the global scope. If that's not the problem, then HMMM.

That's a good point. If you have it global then you can't do it that way. You can declare and set (int b; or int b = 5;), but you can't do colorkeys. Functions like load_img(...) (or whatever it's called) would set something, while even though SDL_SetColorKey(...) sets something it doesnt set the image itself.

So, is it global? Or else, :
Quote:
 {...} HMMM.

##### Share on other sites
Awwwww...yes, it is global. I should have known that was the problem. I will fix that right now! Thanks everyone!

I will edit this post, and tell y'all how it went.

EDIT: Thanks Drew and the Anonymous Poster. That helped a lot! If I could Anonymous Poster, I would bump up your rating, but I can't. I will yours though Drew! Thanks again!

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 11
• 28
• 15
• 41
• ### Forum Statistics

• Total Topics
634837
• Total Posts
3019559
×