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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - RATIU5

Pages: [1]
1
General / sf::Color member not updating on sf::CircleShape draw
« on: February 03, 2021, 09:06:57 pm »
I am trying to change the color of a circle when the mouse is over the circle. I am already successfully detecting when the mouse is over the shape.

// Entity.h:
sf::Color GetSightColor() const
{
    std::cout << "Get m_SightColor: ";
    PrintColor(m_SightColor);
    return m_SightColor;
}
void SetSightColor(const sf::Color& val)
{
    m_SightColor = val;
    std::cout << "Set m_SightColor: ";
    PrintColor(m_SightColor);
}

// Main.cpp:
void Update()
{
...
if (entity.IsInSight(glm::vec2(mouse.x, mouse.y)))
{
    entity.SetSightColor(sf::Color(0, 0, 0, 0));
    std::cout << "Mouse Over Color: ";
    PrintColor(entity.GetSightColor());
} } }

// Entity.cpp:
sf::CircleShape Entity::DrawSight() const
{
    std::cout << "Draw with color: ";
    PrintColor(m_SightColor);
    float radius = GetSightSize();
    sf::CircleShape shape;
    shape.setPosition(GetLoc().x, GetLoc().y);
    shape.setRadius(radius);
    shape.setOrigin(radius, radius);
    shape.setFillColor(GetSightColor());
    return shape;
}
 

The problem is that the circle stays white when the mouse is over it. I logged the colors to make sure the color changes:

Draw with color: (Red: 255, Green: 255, Blue: 255, Alpha: 255)
Get m_SightColor: (Red: 255, Green: 255, Blue: 255, Alpha: 255)
Set m_SightColor: (Red: 0, Green: 0, Blue: 0, Alpha: 0)
Mouse Over Color: Get m_SightColor: (Red: 0, Green: 0, Blue: 0, Alpha: 0)
(Red: 0, Green: 0, Blue: 0, Alpha: 0)
Draw with color: (Red: 255, Green: 255, Blue: 255, Alpha: 255)
Get m_SightColor: (Red: 255, Green: 255, Blue: 255, Alpha: 255)

I don't see what I'm doing wrong. Is this my mistake or a bug?

Specs: Windows 10 x64
SFML: 2.5.1

Pages: [1]
anything