Greetings. Well, I basically have something that draws a 2D array of colored squares. Easy enough, and that part works. I wanted it to scroll, however, as I plan for the random generation to be much wider than a single screen.
view.move(100, 0);
std::cout << view.getCenter().x << "\n";
window.setView(view);
drawWorld(world);
std::cout << window.getView().getCenter().x << "\n";
Simple enough. Now, according to the debug lines, the window does have the same view as what it was set to. The view's center does move.
(http://snag.gy/XfhnG.jpg)
That is what it looks like. It started with the gradient in full view. The black space shows that the view moved. Changing the value (From 100) leaves different amounts of black space. However, it always looks like in the picture. It doesn't scroll.
What am I missing?
Also, the view (and the window) are members of a class, and the view is initialized like so, in the constructor:
view.reset(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
view.setViewport(sf::FloatRect(0, 0, 1, 1));
[code]
Ok. What I expected to happen is that the gradient would keep moving left (or rather, the view moving right and the gradient "falls out" the left), leaving only black. But... it doesn't change visually at all.
Here is that class:
#include "Drawer.h"
#include "BlockSizeCalculator.h"
#include <iostream>
Drawer::Drawer()
{
window.create(sf::VideoMode(500, 500), "");
view.reset(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
view.setViewport(sf::FloatRect(0, 0, 1, 1));
}
void Drawer::drawWorld(World world)
{
int blockSize = BlockSizeCalculator::getBlockSize();
sf::RectangleShape rectangle;
rectangle.setSize(sf::Vector2f(blockSize, blockSize));
for (int x = 0; x < world.getWidth() ; ++x)
for (int y = 0; y < world.getHeight() ; ++y)
{
rectangle.setFillColor(world.getColor(x, y));
rectangle.setPosition(x*blockSize, window.getSize().y - (y*blockSize + blockSize));
window.draw(rectangle);
}
window.display();
}
bool Drawer::draw(World world)
{
view.move(100, 0);
std::cout << view.getCenter().x << "\n";
window.setView(view);
drawWorld(world);
std::cout << window.getView().getCenter().x << "\n";
return false;
}
const sf::RenderWindow & Drawer::getWindow() {return window;}
And called like so:
while (true)
{
drawer.draw(world);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
window.clear();
needs to be called once each time before you draw. I do not see you clearing the screen in your code.
So basically:
window.clear();
//draw all the things
window.display();