Advertisement Jump to content
Sign in to follow this  
yats55

Trying to make background of a sprite transparent, but it wont work

This topic is 2234 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

I'm in the middle of learning sdl, and I'm right now i'm trying out the Transparent part, but the code on the tutorial wont work.
I'm using a 32x32 bmp of a little ship with a the background color 255, 0 ,255 or thats atleast what the graphics program says

#include "SDL.h"
int main(int argc, char *argv[])
{
SDL_Surface *screen , *ship;
SDL_Rect shipRect;
shipRect.x = 0 ;
shipRect.y = 0 ;
atexit(SDL_Quit);
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) exit(1);
SDL_WM_SetCaption("Fryday", NULL);
screen = SDL_SetVideoMode( 256 , 224 , 32 , SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_ANYFORMAT);
SDL_FillRect(screen , NULL , 0x221122);
ship = SDL_LoadBMP("./ship.bmp");
SDL_BlitSurface( ship , NULL , screen , &shipRect );
SDL_SetColorKey( ship, SDL_SRCCOLORKEY, SDL_MapRGB(ship->format, 255, 0, 255) );
SDL_Flip(screen);
SDL_Delay( 8000 );
return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
I think the main problem here is that you need to set the color key on the ship surface before you blit it. Although it would probably help in future if you said what result you got from the program and what result you were expecting rather than "it doesn't work".

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!