Jump to content
  • Advertisement
Sign in to follow this  
Applegenie

[C++] Alpha, Ugly borders around sprite

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

Hello everyone,

I'm still working on that platformer but I encountered another small issue regarding the sprites. I'm trying to cut out sprites from a spritesheet but once I do, these ugly borders persist around the sprite( I'm using a colorkey to remove the background colour ). My plan was just to, instead of using the color: 0, 0xFF, 0xFF as sprite background, to use a simple alpha instead of a background colour, therefor removing said ugly borders. My main problem is, that if I try to use a PNG ( using SDL_image for this ) with a transparent background, it doesn't show any kind of transparency once I load it in. Just a black box around said sprite.

To cut out my sprites, I use 2 for loops:
for(int i = 0; i < rightFrameAmount; i++)
{
rcurrentFrame ++;
clipsRight[rcurrentFrame].x = CHARACTER_WIDTH * i;
clipsRight[rcurrentFrame].y = 0;
clipsRight[rcurrentFrame].w = CHARACTER_WIDTH;
clipsRight[rcurrentFrame].h = CHARACTER_HEIGHT;
}
for(int j = 0; j < leftFrameAmount; j++)
{
lcurrentFrame ++;
clipsLeft[lcurrentFrame].x = CHARACTER_WIDTH * j;
clipsLeft[lcurrentFrame].y = CHARACTER_HEIGHT;
clipsLeft[lcurrentFrame].w = CHARACTER_WIDTH;
clipsLeft[lcurrentFrame].h = CHARACTER_HEIGHT;
}

Color keying out background:
SDL_Surface *load_image( std::string filename )
{
SDL_Surface* loadedImage = NULL;
SDL_Surface* optimizedImage = NULL;
loadedImage = IMG_Load( filename.c_str() );
if( loadedImage != NULL )
{
optimizedImage = SDL_DisplayFormat( loadedImage );
SDL_FreeSurface( loadedImage );
if( optimizedImage != NULL )
{
SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
}
}
return optimizedImage;
}

loading in the images:
bool load_files()
{
//Loading sprite sheets
player_normal = load_image("nwalkspritesheet.png");
player_medium = load_image("mwalkspritesheet.png");
player_large = load_image("lwalkspritesheet.png");
transp = load_image("trans.png");
background = load_image("bg.png");
icon = load_image("icon.bmp");
SDL_WM_SetIcon(icon,NULL);

if(player_normal == NULL || player_medium == NULL || player_large == NULL)
{
return false;
}
if(icon == NULL)
{
return false;
}
return true;
}

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!