Jump to content
  • Advertisement
Sign in to follow this  
Chad Smith

(SDL) Setting Transparent Color Problem

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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 this post


Link to post
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.



Chad.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Drew_Benton
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.


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 this post


Link to post
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.




Chad.


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!


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!