Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


[C++] Alpha, Ugly borders around sprite


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
No replies to this topic

#1 Applegenie   Members   -  Reputation: 109

Like
0Likes
Like

Posted 30 March 2012 - 06:42 AM

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


Sponsor:



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.



PARTNERS