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

Author Topic: How to set a transparent mask from sf::Sprite? (not from sf::Image)  (Read 2258 times)

0 Members and 1 Guest are viewing this topic.

joaojoaojoao

  • Newbie
  • *
  • Posts: 2
    • View Profile
Hi

(This is my first post on SFML, so please..be gentle  :) )

I have a class that contains:

   sf::Texture   mTexture;
   sf::Sprite     mSprite;


I need to create an image with some part that is invisible.
I've read that there is a method called "createMaskFromColor()"

But this method is only used for sf::Image's.

Since I don't have any image on my class (only a texture and a sprite), how can I set a transparent mask from a sprite?

Thank you!

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: How to set a transparent mask from sf::Sprite? (not from sf::Image)
« Reply #1 on: December 23, 2015, 11:05:58 pm »
Loading a texture is effectively a short way of loading an image and then transferring that to a texture so, if you do that manually, you can manipulate the image before it gets to the texture.

sf::Image image;
image.loadFromFile("image.png");
// manipulate image here
sf::Texture texture;
texture.loadFromImage(image);
sf::Sprite(texture);

The image (but not the texture) can be discarded after the texture has loaded from it so the image manipulation can happen inside a function with local scope.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

joaojoaojoao

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How to set a transparent mask from sf::Sprite? (not from sf::Image)
« Reply #2 on: December 24, 2015, 05:47:05 am »
Thank you  :D
It worked!

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: How to set a transparent mask from sf::Sprite? (not from sf::Image)
« Reply #3 on: December 24, 2015, 07:37:56 pm »
You're welcome.
Also, hi and welcome to the forum  :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*