Actually, there's a bug in it. Your drawing loop uses the size of the window, which will change each time you resize it, and the sprite's size, which is a constant.
Your loop would be ok if you used SCREEN_WIDTH and SCREEN_HEIGHT instead of window's size. [...]
I would not call that a bug but intentional: I want to draw the whole screen, not more, not less, and so the screen size (in pixel) is my reference. When the screen size changes I want to draw a different amount of things. And I want to stay pixel precise between source image and screen.
[...]That's because the view (ie. the rectangle that maps into the window) doesn't change, so the size of your 2D world remains the same even after the window has been resized.
That information finally gave me the clue: when the screen changes, the view does not. I actually have to manually update the view to the new screen size, too, to get what I want.
In my example application that would like this, where now a) event handling comes before drawing and b) RenderWindow.SetView is called:
// big loop
while (Looping)
{
// poll events
while (MyRenderWindow.GetEvent(MyEvent))
{
// check whether resized
if ((MyEvent.Type == sf::Event::Resized)) {
// >>> set new view !!! <<<
MyRenderWindow.SetView(
&sf::View(
sf::FloatRect(
0.0f,
0.0f,
(float) MyRenderWindow.GetWidth(),
(float) MyRenderWindow.GetHeight())));
}
}
// loop over screen
for (Y = 0; Y < (int) MyRenderWindow.GetHeight(); Y += SPRITE_HEIGHT_DEST)
{
for (X = 0; X < (int) MyRenderWindow.GetWidth(); X += SPRITE_WIDTH_DEST)
{
// draw sprite
MySprite.SetPosition((float) X, (float) Y);
MyRenderWindow.Draw(MySprite);
}
}
Unfortunately I could not find any hint in the documentation about the relation of "screen size changes" and "view size stays the same". In addition I (personally) consider that default behavior quite unintuitive. I would prefer that the view internally would get adjusted automatically with me worrying only about screen size in pixel. If you have good reasons against that, a hint in the documentation of "sf::Event::Resized" or so would be helpful for newbies like me.
Nevertheless thanks for your effort.