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

Author Topic: [SFML 2.0] Sprites and Transparency  (Read 17746 times)

0 Members and 1 Guest are viewing this topic.

Moonkis

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
[SFML 2.0] Sprites and Transparency
« on: April 19, 2012, 10:59:21 pm »
Hello to the SFML forum how are you all doing?
I'm very new to the SFML library and to game programming as well though I'm slowly learning.

I just recently finished making all the linking work ( Debug and Release ) and wrote "the" basic RenderWindow layout to make sure it worked correctly.

Now I'm running into some issues drawing Images to the screen, the "magenta color" or well the color I wan't to be transparent is not.

I figured out by goggling that I could use the "createMaskFromColor(sf::Color::Magenta)" to make it invisible thus only displaying what I want. But I need to call that function for every image that I want to apply it to.

I was just curious if this was the "standard" or "right" way of doing it? And if so, what it is it called in programming terms? Is it the same as "Masking" sprites?

Slightly Off-Topic
To be able to draw sprites to the screen I need to use the "RenderWindow.draw()" method. The object is not copy-able so passing it is no choice ( if not by reference or with a pointer ).

How does people usually draw lot of game objects that are inside a vector? Do thy pass it to an "Object Managers" draw function? The same with Event do people pass it to every objects Update function as well? Since the RenderWindow is the only object that is able to poll for the keyboard events and stuff.

The structure of SFML is a bit wonky for me since I'm coming from C# and XNA. Hopefully someone will explain the "generic" flow of an SFML game that is "bigger" than pong for example.



Kind regards Moonkis

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: [SFML 2.0] Sprites and Transparency
« Reply #1 on: April 19, 2012, 11:44:18 pm »
If you don't want to hit your head against a wall (exagerated), you can simply use .png images with transparancy.

I think there is a way to mask colors, but I can't answer that

Moonkis

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: [SFML 2.0] Sprites and Transparency
« Reply #2 on: April 20, 2012, 12:30:16 am »
If you don't want to hit your head against a wall (exagerated), you can simply use .png images with transparancy.

I think there is a way to mask colors, but I can't answer that

Wait, how does that work? I have the images I want to be the "magenta" color to be transparent in but it still shows the color when I'm trying to draw the image to the screen.

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: [SFML 2.0] Sprites and Transparency
« Reply #3 on: April 20, 2012, 12:42:38 am »
If you don't want to hit your head against a wall (exagerated), you can simply use .png images with transparancy.

I think there is a way to mask colors, but I can't answer that

Wait, how does that work? I have the images I want to be the "magenta" color to be transparent in but it still shows the color when I'm trying to draw the image to the screen.

The PNG image files have an alpha canal. So in photoshop, or paint or whatever, you can put transparancy on your image. Images with transparent areas are well displayed by SFML.

You can use your method too (transform a certain color in transparent). But I can't help you in that way, because I just don't know how to do.

IMO it's easiest to do your images with transparency from the beggining (in your image editor), 'cause there's nothing to do to handle it with SFML later.

Moonkis

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: [SFML 2.0] Sprites and Transparency
« Reply #4 on: April 20, 2012, 01:26:21 am »
Editing the transparency inside an editor is a solution I guess but I just want to clarify something
does "createMaskFromColor()" affect the performance in any way after it has been used on an image?
Also does it affect memory greatly?

In other words would I expect performance issues  using "createMaskFromColor()" in larger projects?
Sorry for the "noob" questions but as I said I'm new to SFML and the way it works.

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: [SFML 2.0] Sprites and Transparency
« Reply #5 on: April 20, 2012, 01:28:06 am »
Editing the transparency inside an editor is a solution I guess but I just want to clarify something
does "createMaskFromColor()" affect the performance in any way after it has been used on an image?
Also does it affect memory greatly?

In other words would I expect performance issues  using "createMaskFromColor()" in larger projects?
Sorry for the "noob" questions but as I said I'm new to SFML and the way it works.

I'm note able to answer that question, anyway the answer interest me ^^

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [SFML 2.0] Sprites and Transparency
« Reply #6 on: April 20, 2012, 08:16:38 am »
Quote
does "createMaskFromColor()" affect the performance in any way after it has been used on an image?
No, it just transforms the alpha component of pixels from 255 to 0. In other words, it does what you'd do in an image editor.

Quote
Also does it affect memory greatly?
No, all pixels have an alpha component, this function just change their value.

Quote
In other words would I expect performance issues  using "createMaskFromColor()" in larger projects?
Absolutely zero impact.
Laurent Gomila - SFML developer

 

anything