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 - Turbo

Pages: [1]
1
Graphics / sf::RectangleShape.setFillColor() is not working
« on: September 25, 2021, 05:03:04 pm »
Hello people from the SFML community. Recently I was meddling with the library and I was trying to make an sf::RectangleShape change its color whenever I hover my mouse over it, which is something I have done before without any issues. However, this time I don't understand what seems to be going wrong.
Here is the bit of code where I change the shape's color:
void Node::update(sf::RenderWindow*& window)
{
        bool mouse_over = IsMouseOver(this->rect.getGlobalBounds(), window);

        if (mouse_over)
        {
                this->rect.setFillColor(sf::Color( //Doesn't work
                        this->color.r + 30.0f,
                        this->color.g + 30.0f,
                        this->color.b + 30.0f
                ));
                printf("r: %d, g: %d, b:%d\n",
                        rect.getFillColor().r,
                        rect.getFillColor().g,
                        rect.getFillColor().b);
        }
        else if (!mouse_over)
        {
                this->rect.setFillColor(this->color); //Doesn't work either
                printf("r: %d, g: %d, b:%d\n",
                        rect.getFillColor().r,
                        rect.getFillColor().g,
                        rect.getFillColor().b);
        }
}
 
Before anyone suggests that the order of execution is wrong, let me show you how I'm using this method:
void NodeManager::updateNodes(sf::RenderWindow*& window) //Updates every node in the nodes matrix
{
        for (auto i : nodes)
                for (auto j : i)
                        j.update(window);
}
 
void Program::update(void)
{
    nodeManager->updateNodes(window);
}
void Program::run(void)
{
    while (window->isOpen())
    {
        sf::Event event;
        while (window->pollEvent(event))
            this->events(event);
        this->update(); //Method is executed within the update method before anything is drawn to the screen
        this->draw();
    }
}
 
void Program::draw(void) //The draw method
{
    window->clear();
    //Draw things here ==============================
    nodeManager->drawNodes(window);
    //===============================================
    window->display();
}
 
I need your help, because I have no idea what the issue is. I've been trying to figure this out for a while now and I'm starting to question why I'm even doing this in the first place.

Pages: [1]
anything