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

Author Topic: sf::Sprite::getColor() return value problem  (Read 2880 times)

0 Members and 1 Guest are viewing this topic.

Ganado

  • Newbie
  • *
  • Posts: 34
  • Moo, I say.
    • View Profile
    • FOnline Engine, check it out.
sf::Sprite::getColor() return value problem
« 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.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile

Ganado

  • Newbie
  • *
  • Posts: 34
  • Moo, I say.
    • View Profile
    • FOnline Engine, check it out.
Re: sf::Sprite::getColor() return value problem
« Reply #2 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.