Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: partially transparent sprites  (Read 2965 times)

0 Members and 1 Guest are viewing this topic.

sludge

  • Newbie
  • *
  • Posts: 24
    • View Profile
partially transparent sprites
« on: August 20, 2010, 02:33:14 am »
I want to be able to display a sprite on the screen and have certain parts of that sprite be transparent.

Let me explain by example.  Suppose that I have a picture of a stick figure.  If I were to load this picture into sfml as an image, set it to sprite, define its subrect, and then display the resulting sprite, I would see a white box with a stick figure in it above my background.

I want the white areas of the sprite to be transparent so that only the stick-figure part of the subrect is rendered.  The background will then appear where the white parts were previously.

I'm sure there is a simple solution to this problem... Any ideas?

dunce

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
partially transparent sprites
« Reply #1 on: August 20, 2010, 04:45:39 am »
class Image has this method:
Code: [Select]
void  CreateMaskFromColor (const Color &color, Uint8 alpha=0)
  Create a transparency mask from a specified colorkey.

Create a mask from white colored area for the image your sprite uses and this part of the sprite will become transparent.

sludge

  • Newbie
  • *
  • Posts: 24
    • View Profile
partially transparent sprites
« Reply #2 on: August 20, 2010, 09:50:00 am »
that worked like a charm.  Thank you