I'm making a simple game with SFML (C++) where your cursor turns into a reticule and you just shoot stuff on a scrolling background.
I'm having trouble with the scrolling background (which I am using 2 sprites from the same image and moving one sprite to the end of the window as it goes off the window). When it moves on to the next sprite there is a flickering bar and I'm wondering what i've done wrong to cause this.
(I'm aware the code isn't very optimized at all without any classes or functions and having everything crammed into main but this will have to do for now).
Any suggestions / criticisms will be good :D
Damn, originally posted in lounge section and had to repost /palm
I don't think I can find one but if I change the line Background[1].SetPosition((Background[0].GetPosition().x + Background[0].GetSize().x) - 1, 0);
and add a - 1,
The flickering line definitely becomes smaller but it is still noticeable as it scrolls.
I've had this problem (the flickering line) using DirectX (ID3DXSprite) when I didn't control conversion from floating-point to integer myself, because of floating-point imprecision.
Just to be sure this is not your problem, you could make sure Background[0]'s position is also being cast to an integer, because if just one of the sprites is flickering, the line will show up.
In the console I print their positions when the transition happens and these are some values -
1364 -2 CHECK 0
1362 -4 CHECK 1
CHECK 0 having the 1st value being background[0]'s position
CHECK 1 having the 1st value being background[1]'s position
The screen I test it on is 1366 x 768, so the values do add up fine.
When I set the sprite up, I do resize the image to fit my screen -
1 2 3 4 5
for (int i = 0; i < 2; ++i)
{
Background[i].SetImage(BackgroundImage);
Background[i].Resize(WindowWidth, WindowHeight);
}
Funny thing is, when I change the part where the sprites move, the line doesn't flicker anymore (refer back to problem image but imagine that it is now a constant black line).
If I change it from the frame-dependent movement formula from the first 2 lines to the last 2 lines, there is no more flickering. ElapsedTime is App.GetFrameTime().