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

Author Topic: Getting object from picture, not background  (Read 1794 times)

0 Members and 1 Guest are viewing this topic.

dusan

  • Newbie
  • *
  • Posts: 12
    • View Profile
Getting object from picture, not background
« on: May 27, 2012, 08:31:56 pm »
Hello,
I am still newbe in SFML since I started like a day ago :D .
So far I created TicTacToe game you can see it here.
Now I moved on Pong game and I have a problem.
In this game I have ball picture it is simple ball with white background. But my window background is other picture (green color) that I found on google. So when I draw ball on that background I saw rectangle - the whole image that ball is.
I just want to make ball visible not background
Is there any way of achieving this ?

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
Re: Getting object from picture, not background
« Reply #1 on: May 27, 2012, 10:26:18 pm »
If your ball image is there with a white rectangle around it, sounds like you need the area around the ball to be alpha level 0 (transparent). You can do this using an image editor like Gimp.
{much better code}

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: Getting object from picture, not background
« Reply #2 on: May 28, 2012, 01:47:24 am »
3 possibilities :
- edit your image so that it has a transparent background, like Jove said
- take an image that already has a transparent background
- use sf::Image::createMaskFromColor(sf::Color::White)

The latest one will tell SFML that the white color (background of your ball image) should not be displayed.
Want to play movies in your SFML application? Check out sfeMovie!

dusan

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Getting object from picture, not background
« Reply #3 on: May 28, 2012, 07:03:02 pm »
Ty for replays.
sf::Image::createMaskFromColor(sf::Color::White) worked great!
And editing image is also easier and maybe better solution than createMaskFromColor.
Ty anyway it helped a lot!

 

anything