SFML community forums

Help => Graphics => Topic started by: bszandras on May 21, 2020, 09:28:51 am

Title: PixelPicking with sf::Image
Post by: bszandras on May 21, 2020, 09:28:51 am
I am pretty sure I am missing something, but I have been Google-ing this for the last week.
My problem is, that the underneath can not find any pixels Blue (0, 0, 255), and I have absolutely no idea why it is not working. :(

Little explanation:
startingCave is the name of the Image
what I am trying to achive, is that with the two for loops, the code should go through the image row by row and everytime it finds a blue pixel it should set the if statement true


        Vector2f globalCurrentPos;
        sf::Color pixelColor;

        for (int y = 0; y < startingCave.getSize().y; y++) {
                for (int x = 0; x < startingCave.getSize().x; x++) {

                        globalCurrentPos.x = originDirt.x + x ;
                        globalCurrentPos.y = originDirt.y + y ;

                        pixelColor == startingCave.getPixel(x, y);
                        if (pixelColor == sf::Color(0, 0, 255)) {
                                //createDirt(world, globalCurrentPos);

                                debugText.setString("found");
                        }
                }
        }
Title: Re: PixelPicking with sf::Image
Post by: bszandras on May 21, 2020, 11:27:01 am
Figured it out!

In case someone, a beginner like me does not know, the "==" operator does not set a color in sf::Color, it compares colors, so my attempt, to set the variable "pixelColor" as the color of the current pixel the loop is looking at failed allways.
Title: Re: PixelPicking with sf::Image
Post by: Athenian Hoplite on May 21, 2020, 01:25:54 pm
.. the "==" operator does not set a color in sf::Color, it compares colors ...

The "==" operator never sets anything. It is always used to do comparisons, when valid, returning a boolean.