when you resize the window always set a new view.
basicSettings.screenx and basicSettings.screeny doing strange offsets.
sf::View v( sf::FloatRect( sf::Vector2f( basicSettings.screenx, basicSettings.screeny ), \
sf::Vector2f( basicSettings.screenw, basicSettings.screenh ) ) );
try
sf::View v( sf::FloatRect( sf::Vector2f( 0, 0 ), \
sf::Vector2f( basicSettings.screenw, basicSettings.screenh ) ) );
example
#include <SFML/Graphics.hpp>
sf::View calcView(const sf::Vector2u &windowsize, const sf::Vector2u &designedsize)
{
sf::FloatRect viewport(0.f, 0.f, 1.f, 1.f);
float screenwidth = windowsize.x / static_cast<float>(designedsize.x);
float screenheight = windowsize.y / static_cast<float>(designedsize.y);
if(screenwidth > screenheight)
{
viewport.width = screenheight / screenwidth;
viewport.left = (1.f - viewport.width) / 2.f;
}
else if(screenwidth < screenheight)
{
viewport.height = screenwidth / screenheight;
viewport.top = (1.f - viewport.height) / 2.f;
}
sf::View view( sf::FloatRect( 0, 0, designedsize.x , designedsize.y ) );
view.setViewport(viewport);
return view;
}
int main()
{
const sf::Vector2u designedsize(320,200);
sf::RenderWindow app(sf::VideoMode(800, 400), "SFML window");
app.setView(calcView(app.getSize(), designedsize));
while (app.isOpen())
{
sf::Event event;
while (app.pollEvent(event))
{
if (event.type == sf::Event::Closed)
app.close();
if (event.type == sf::Event::Resized)
app.setView(calcView(sf::Vector2u(event.size.width, event.size.height), designedsize));
}
app.clear();
sf::CircleShape circle(5);
for(int y = 0; y < designedsize.y/10; ++y)
{
for(int x = 0; x < designedsize.x/10; ++x)
{
circle.setPosition(x * 10, y * 10);
circle.setFillColor( (x + y) & 1 ? sf::Color::Blue:sf::Color::Green);
app.draw(circle);
}
}
app.display();
}
return 0;
}