Sign in to follow this  
Followers 0
Applegenie

[C++] Alpha, Ugly borders around sprite

0 posts in this topic

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:
[code]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;
}[/code]
Color keying out background:
[code]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;
}[/code]
loading in the images:
[code]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;
}[/code]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0