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

Author Topic: [Solved] Opacity for Sprites?!  (Read 18183 times)

0 Members and 1 Guest are viewing this topic.

BloodGod

  • Newbie
  • *
  • Posts: 10
    • View Profile
[Solved] Opacity for Sprites?!
« on: May 20, 2008, 02:55:20 pm »
Sorry, i can't find something about opacity for sprites :/ Is this even supported by sfml? If yes, can someone give me a hint, how to change the opacity? :D  
Otherwise it would be great to find a method like setOpacity(int opacity) in one of the next versions =)

Btw: SFML is hardcore
Great work!!! =D

Sincerely,
BloodGod
Verlässt du dich auf andere, bist du selbst verlassen ;)

Redien

  • Newbie
  • *
  • Posts: 30
    • View Profile
[Solved] Opacity for Sprites?!
« Reply #1 on: May 20, 2008, 03:05:41 pm »
SFML uses an alpha channel to store opacity as it uses the RGBA colorspace.
http://en.wikipedia.org/wiki/RGBA_color_space

You can use the method SetColor to change the alpha value.
http://www.sfml-dev.org/tutorials/graphics-sprite.php

BloodGod

  • Newbie
  • *
  • Posts: 10
    • View Profile
[Solved] Opacity for Sprites?!
« Reply #2 on: May 20, 2008, 03:11:33 pm »
OMG, right -.- Thank you very much!!! =D
But what about images without an Alphachannel, does it work anyway? I mean does the sprite class handle it somehow?
Can't test it right now, i'm not at home :/

Thanks a million =D

Sincerely,
BloodGod

EDIT: Ok ok...sorry now i know :) Read faster than my brain could understand -.-
Verlässt du dich auf andere, bist du selbst verlassen ;)

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
[Solved] Opacity for Sprites?!
« Reply #3 on: May 21, 2008, 11:28:21 am »
I'd suggest using png format for images personally as then you get lossless compression (no jpeg artifacts or anything distorting your image) and an alpha channel but if you don't want to (using jpg, bmp or another format without built in alpha support) then you could always use the function I suggested here and use a separate image as a greyscale alpha channel (you may need to adjust how the colour channel values are blended together :))

BloodGod

  • Newbie
  • *
  • Posts: 10
    • View Profile
[Solved] Opacity for Sprites?!
« Reply #4 on: May 21, 2008, 06:08:33 pm »
Hi workmad3 :),

My program must handle jpeg etc... it has something to to with ergonomics, cause some users rather like to use JPEG instead of PNG (It will be some kind of HTML parser ;) )

I think I should never use the term alphachannel again  :?  I always barter this term with simple opacity. Of course I would use png, i think using greyscale images for alphachannel infos with e.g. jpeg is (in this case) a waste of time. But thank you for the advice =) I'll store this function in my little coding DB hehe :D

Sincerely,
BloodGod
Verlässt du dich auf andere, bist du selbst verlassen ;)

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
[Solved] Opacity for Sprites?!
« Reply #5 on: May 21, 2008, 10:58:39 pm »
It would be very simple to change the function into one that could take an image and alter all the alpha values to a specific value as well :) Or (possibly better) to subtract an amount from the alpha values to make it more transparent (or less) as then it will preserve the existing transparency :)

And yeah... functional requirements (such as requiring jpeg support) are always annoying. There are some great ones on my project at work that just seem to be there to make things awkward (such as allowing the user to regenerate encryption keys... across a mobile network... that could fail at any point... with no transaction support. So many defects with that, mostly to do with the user selecting it when they have no signal and destroying their devices encryption keys :/).

lohr

  • Newbie
  • *
  • Posts: 15
    • View Profile
[Solved] Opacity for Sprites?!
« Reply #6 on: June 26, 2008, 07:48:30 am »
Hm I think my problem goes in this direction...
I have a PNG format and want to draw this, but the sprite is then a rectangle, if i have a more complex building in it (like a circle), how could i make it that all around the circle is splitted away from the rectangle?

Is there any method?

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
[Solved] Opacity for Sprites?!
« Reply #7 on: June 26, 2008, 08:24:36 am »
Create a circle in your rectangular image, making sure all the pixels around your circle are transparent. That'll make the sprite appear as a circle rather than a rectangle.

lohr

  • Newbie
  • *
  • Posts: 15
    • View Profile
[Solved] Opacity for Sprites?!
« Reply #8 on: June 26, 2008, 09:13:56 am »
What do you mean with "transparent", white?

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
[Solved] Opacity for Sprites?!
« Reply #9 on: June 26, 2008, 09:21:11 am »
do a google search on alpha transparency to see what he means :)

lohr

  • Newbie
  • *
  • Posts: 15
    • View Profile
[Solved] Opacity for Sprites?!
« Reply #10 on: June 26, 2008, 09:40:16 am »
Okay, so i have to work with Gimp ^^
I think Paint in windows cant do that, right? ^^

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
[Solved] Opacity for Sprites?!
« Reply #11 on: June 26, 2008, 03:52:47 pm »
Quote from: "lohr"
Okay, so i have to work with Gimp ^^
I think Paint in windows cant do that, right? ^^


No, MS Paint can't do it.

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
[Solved] Opacity for Sprites?!
« Reply #12 on: October 03, 2011, 07:02:51 pm »
I know this thread is a little old, but anyways...

Is there a way to make the a specific color on an image transparent?
Like to just show the silhouette of a character and not the whole squared image?
Thank you.



Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Solved] Opacity for Sprites?!
« Reply #13 on: October 03, 2011, 08:10:38 pm »
Image::CreateMaskFromColor.
Laurent Gomila - SFML developer