So i did my best to create a complete and minimal example, here's the code:
#include <SFML/Graphics.hpp>
int main()
{
sf::Vector2i screenDimensions(1280, 720);
sf::RenderWindow wnd(sf::VideoMode(screenDimensions.x, screenDimensions.y), L"Test");
sf::View cam(wnd.getDefaultView());
wnd.setView(cam);
const int level[8][16] =
{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
wnd.setFramerateLimit(60);
// Create clock to measure frame time
sf::Clock frameClock;
wnd.setKeyRepeatEnabled(false);
sf::RectangleShape shape(sf::Vector2f(10.f, 10.f));
shape.setPosition(screenDimensions.x / 4.f, screenDimensions.y / 2.f);
sf::Vector2f movement(0.f, 0.f);
float speed = 200.f;
while (wnd.isOpen())
{
sf::Event event;
while (wnd.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
wnd.close();
break;
case sf::Event::KeyPressed:
if (event.key.code == sf::Keyboard::I)
wnd.setFramerateLimit(0);
else if (event.key.code == sf::Keyboard::O)
wnd.setFramerateLimit(60);
break;
}
}
sf::Time frameTime = frameClock.restart();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::F))
shape.setPosition(screenDimensions.x / 4.f, screenDimensions.y / 2.f);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A) && !sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
movement.x -= speed;
shape.move(movement * frameTime.asSeconds());
movement = sf::Vector2f(0.f, 0.f);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D) && !sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
movement.x += speed;
shape.move(movement * frameTime.asSeconds());
movement = sf::Vector2f(0.f, 0.f);
}
if (shape.getPosition().x + shape.getSize().x > screenDimensions.x / 2)
{
cam.setCenter(shape.getPosition().x + (shape.getSize().x / 2), shape.getPosition().y);
wnd.setView(cam);
}
wnd.clear();
sf::View veiw = wnd.getView();
sf::FloatRect screenRect(veiw.getCenter() - (veiw.getSize() / 2.f),
veiw.getSize());
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 16; j++)
{
if (screenRect.intersects(sf::FloatRect(level[i][j] * 32, level[i][j] * 32, 32, 32)))
{
sf::RectangleShape rect(sf::Vector2f(32.f, 32.f));
rect.setPosition(j * 32, i * 32);
wnd.draw(rect);
}
}
}
wnd.draw(shape);
wnd.display();
}
return 0;
}
Sorry for taking so long to reply.
On a side note, i'm now compiling with Visual Studio 2015.