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

Pages: [1]
1
hi,
I am really clueless about the following:

I got my game-loop in which I call the draw method of my Map class.
Additionally, I call setFillColor on a certain sf::RectangleShape of my Map class.
The debugger tells me that the color has succesfully changed.

However, it will only be visually updated in the following draw method:

void Map::draw(sf::RenderWindow* w)
{
    for (int x = 0; x < MAP_WIDTH; x++)
    {
         for (int y = 0; y < MAP_HEIGHT; y++)
         {
                int i = x * MAP_HEIGHT+ y;
                w->draw(tiles[i]);
         }
    }
}
 

Initially, I used the following method to draw my tiles which didn't work:
void Map::draw(sf::RenderWindow* w)
{
    for (int i = 0; i < tiles.size(); i++)
    {
         w->draw(tiles[i]);
    }
}
 

It draws all tiles, but it doesn't draw the updated FillColor, even though the FillColor for the certain Tile changed its value succesfully.

I double checked the values of both i variables(both, in debugger and I printed them in a log file).
They are exactly the same.
Both starts at 0 and increase up to 63.
It just makes no sense to me.

As mentioned, it is working with the first method but not with the second and I'm kinda afraid that I do something horrible wrong.


My tiles are just a member of my Map Class:
std::vector<sf::RectangleShape> tiles;
 

For references the init method for my map:
bool Map::initialize()
{
        for (int x = 0; x < MAP_WIDTH; x++)
        {
                for (int y = 0; y < MAP_HEIGHT; y++)
                {
                        sf::RectangleShape tile;
                        tile.setFillColor(sf::Color::Cyan);
                        tile.setOutlineColor(sf::Color::Blue);
                        tile.setOutlineThickness(1.0f);

                        tile.setPosition(START_X + x*tile_width, START_Y + y*tile_height);
                        tile.setSize(sf::Vector2f(tile_width, tile_height));

                        tiles.push_back(tile);
                }
        }
        return true;
}
 

and the update of the fill color:
void GsGame::highlightTile()
{
        PositionComponent* pos = entities[0].getComponent<PositionComponent>();

        //it returns the right tile, checked it
        sf::RectangleShape* tile = map.positionToTile(pos->x, pos->y);
       
        //breakpoint at setFillColor is only reached once, so the FillColor must have changed succesully.
        if (tile->getFillColor() != sf::Color::Yellow)
                tile->setFillColor(sf::Color::Yellow);

}
 

And finally, my game draw method:
void GsGame::draw()
{
        window->clear(clearColor);
        highlightTile();
        map.draw(window);
        window->display();
}
 


Edit://
Might also add:
I am using Visual Studio Ultimate 2013
and the latest source of sfml 2.1

Pages: [1]