SFML community forums

Help => Graphics => Topic started by: Ganado on September 09, 2013, 06:13:25 am

Title: sf::Sprite::getColor() return value problem
Post by: Ganado on September 09, 2013, 06:13:25 am
Okay so the problem I have right now is that when I use getColor().r on a sprite object (.r, .g, or .b, it doesn't matter which), I have the console output the return value, but the value it returns is a mystery.

I thought it would return an integer value between 0 and 255, yet it only seems to return weird characters.

Here's my cut-down code:
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    srand((unsigned)time(NULL));
    sf::RenderWindow Window;
    Window.create(sf::VideoMode(400, 255), "My Title", sf::Style::Close);
    Window.setVerticalSyncEnabled(true);
    Window.setKeyRepeatEnabled(false);

    sf::Texture tileTexture;
    if (!tileTexture.loadFromFile("tile.png"))
        {std::cout << "Error: Could not load block_grid image" << std::endl; return -1;}

    std::vector<sf::Sprite> tileSprites(10, sf::Sprite(tileTexture));

    tileSprites[0].setColor(sf::Color(rand()%256, rand()%256, rand()%256));
    std::cout << tileSprites[0].getColor().r; // this returns a random symbol, such as Greek character
    // For example, if I make the first parameter of the sf::Color(2, #, #), getColor().r returns a smiley face symbol.
    //the rest of the code isn't important
}
 

So, am I doing something wrong, or is getColor() supposed to return its value like that? Thank you for reading.
Title: Re: sf::Sprite::getColor() return value problem
Post by: G. on September 09, 2013, 06:43:09 am
http://en.sfml-dev.org/forums/index.php?topic=2448.msg15946#msg15946
Read Nexus' answer. ;)
Title: Re: sf::Sprite::getColor() return value problem
Post by: Ganado on September 09, 2013, 06:48:14 am
Ah okay, I can't try it right now, but Nexus' answer makes sense. My preliminary search before making the thread was searching for keywords like getcolor, so I didn't find anything good. Anyway, thanks.