I have read a thread about this:
http://en.sfml-dev.org/forums/index.php?topic=9320.0 but, even after looking at the example, I am unable to add this into my game.
I want a circle of
just transparency - no white borders, or any pretty effects - to follow the player. The darkness layer will not always be present, as it needs to slowly fade in/out, so the rectangle which the circle is drawn on needs to be black and the same opacity as the darkness layer.
Here is what I have so far:
//class Darkness
sf::RenderTexture m_Layer;
sf::RenderTexture m_lighttexture;
sf::Sprite m_Sprite;
sf::Sprite m_light;
/////
m_Layer.create(view->getSize().x,view->getSize().y);
init_light();
void Darkness::init_light(){
m_lighttexture.create(100,100);
m_lighttexture.clear();
sf::CircleShape temp(50);
temp.setOrigin(50,50);
temp.setFillColor(sf::Color(255,255,255,0));
temp.setPosition(sf::Vector2f(50.f, 50.f));
m_lighttexture.draw(temp, sf::BlendNone);
m_light.setTexture(m_lighttexture.getTexture(),true);
m_light.setOrigin(50,50);
}
and
void Darkness::render(){
m_Layer.clear(sf::Color(0,0,0,opacity));
if(displaylight){
m_Layer.draw(m_light,sf::BlendNone);
}
m_Layer.display();
m_Sprite.setTexture(m_Layer.getTexture());
Game::window->draw(m_Sprite);
}
What happens is there is a black rectangle on top of the player at all times - not transparent.