Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

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

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 bigbadbear9885   Members   

177
Like
0Likes
Like

Posted 06 December 2012 - 01:04 AM

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;
}

Attached Files

  • Attached File  ship.bmp   2.05KB   74 downloads


#2 RulerOfNothing   Members   

1425
Like
1Likes
Like

Posted 06 December 2012 - 02:38 AM

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".

#3 ptrrf   Members   

410
Like
1Likes
Like

Posted 06 December 2012 - 11:50 AM

You must call SDL_SetColorKey BEFORE blit the desired surface.

A good practice is load the image on the beginning of the application, and set the color key after.

(Sorry if I wrote something wrong.)

Edited by ptrrf, 06 December 2012 - 11:53 AM.


#4 Endurion   Members   

5318
Like
1Likes
Like

Posted 07 December 2012 - 08:24 AM

To detail ptrrfs answer even more, load the image once, and set the color key on that image once. The color key is then a property of that SDL_Image.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.