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.


Messages - RATIU5

Pages: [1]
1
General / Re: sf::Color member not updating on sf::CircleShape draw
« on: February 04, 2021, 09:04:31 pm »
Right after the Update() function gets called, I call the Draw() function which calls the DrawSight() function. The Entity class has quite a few variables, and functions which would have been quite a lot of code if I posted it all.

In the Entity class, I have a private variable
sf::Color m_SightColor;
which by default is (Red: 255, Green: 255, Blue: 255, Alpha: 255). I have setters/getter for this variable, and when I return the sf::CircleShape shape; to draw, I set the color of the shape with the GetSightColor() function. I tried this using the private member on its own without the function (m_SightColor) and it yielded the same result: (Red: 255, Green: 255, Blue: 255, Alpha: 255); even though I change it when the mouse moves over it.

The log shows that it changes, but it somehow resets after. I tried passing the color not as a reference to the setter to copy it, but it still resets. Would any other functions help you understand what's going on that I should show?

2
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