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

Author Topic: how do i set sprite transparancy?  (Read 1682 times)

0 Members and 1 Guest are viewing this topic.

bobingabout

  • Newbie
  • *
  • Posts: 47
    • View Profile
how do i set sprite transparancy?
« on: March 15, 2012, 10:49:38 am »
I'm converting something I wrote in SDL to use SFML 1.6.

The sprites i have are in 8 bit BMP image format, and i know the colour code of the image background.
Basicly, what i want to do is, draw everything in the loaded image except this background colour when i draw the sprite. in SDL, its pretty easy, you just give an instruction the RGB colour code, and its done.

I've looked through the documentation on images and sprites, but don't see how i could do it.

Short of changing the file format of every image to a file format that includes alpha, such as 32bit PNG files, with the transparancy already set before loading them, I don't know what i should do.

any help?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
how do i set sprite transparancy?
« Reply #1 on: March 15, 2012, 10:52:32 am »
Image::CreateMaskFromColor
Laurent Gomila - SFML developer

bobingabout

  • Newbie
  • *
  • Posts: 47
    • View Profile
how do i set sprite transparancy?
« Reply #2 on: March 15, 2012, 11:02:16 am »
Doh, yes, now that you've told me the name, i can see it in the documentation on this page http://www.sfml-dev.org/documentation/1.6/classsf_1_1Image.php

I shall give it a try.

bobingabout

  • Newbie
  • *
  • Posts: 47
    • View Profile
how do i set sprite transparancy?
« Reply #3 on: March 15, 2012, 11:35:19 am »
Okay, an unrelated question, well, semi related, since its still graphics.
I wasn't sure if i should just continue, or start another topic, but... okay.

Even though i'm setting scale to 1, centre set to the default 0,0, and position to an int value, say 200,100 as an example, it seems to draw my sprite between the pixels, causing a blur, and since its only 8x8 pixels in size, white on black, its basicly a grey blob.

Since i will be working exclusively with Pixel art (as a modern example, think terraria), even if the position is set to a fraction of a pixel, I always want it to draw  pixel for pixel on the screen.
How would i go about doing this?

EDIT:
Nevermind, i got it. Image.SetSmooth(false);
I looked at window, view and sprite before posting, and forgot about the image itself.

Bigz

  • Full Member
  • ***
  • Posts: 154
    • View Profile
    • Bigz.fr
how do i set sprite transparancy?
« Reply #4 on: March 15, 2012, 12:05:24 pm »
Hm, I don't think it draws your sprite at a float position, as it's actually not possible. But this blending of colors seems to be something more like a filter which changes the colors. Does the "smooth" option on your image is set to true ?

EDIT : well, you find it by your own =)