OS: Windows 7x64
Graphics Card: Radeon 7950
SFML: 2.3, static
I'm having an issue which may just stem from my lack of understanding of how this should be set up. Due to the amount of classes I have, it would be a pain to put all my code here but I'll do my best to simplify it so it's post friendly.
Edit: Created a new project with just a main.cpp to isolate the issue. Attached the images I used.
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(1024, 768), "Game");
sf::View gameView;
sf::Texture texture, texture2;
gameView.setSize(sf::Vector2f(1024, 768));
texture.loadFromFile("image.png");
texture2.loadFromFile("image2.png");
int playerX = 5;
int playerY = 5;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::KeyPressed)
{
if (event.key.code == sf::Keyboard::Up)
{
playerY--;
}
else if (event.key.code == sf::Keyboard::Down)
{
playerY++;
}
else if (event.key.code == sf::Keyboard::Left)
{
playerX--;
}
else if (event.key.code == sf::Keyboard::Right)
{
playerX++;
}
}
}
window.clear();
window.setView(gameView);
for (int x = 0; x < 10; ++x)
{
for (int y = 0; y < 10; ++y)
{
// Note: This is not actually how I handle sprites, it's done in another class but in order to simplify it I'm just putting it here.
sf::Sprite sprite;
sprite.setTexture(texture);
sprite.setPosition((x - y) * 64, (x + y) * 32);
window.draw(sprite);
if ((x == playerX) & (y == playerY))
{
sf::Sprite player;
player.setTexture(texture2);
player.setPosition((x - y) * 64, (x + y) * 32 - 64);
window.draw(player);
gameView.setCenter(player.getPosition());
}
}
}
window.display();
}
return 0;
}
So, it's a 10x10 isometric 2D map of "texture" sprites. When it gets to the coordinates the player is on, it draws the player then sets the view to be centered on the player. I have no idea if this is the normal way to go about handling this, I'm kinda just figuring it out as I go (I prefer this method to following full tutorials as I enjoy encountering problems and going through the steps to fix them. Helps me learn better).
The problem is when I move around, the player sprite stutters a bit. Maybe every 5-10 moves, it will draw the player one step ahead of where they should be then correct it immediately. I tried to capture this on video but the screen corrects itself so quickly that the FPS wasn't high enough on the video to catch it.
Instead, I made a series of screenshots to show this
1) Start position
2) I move once, everything normal. The player moves, the view follows
3) I move again, and for a split second, I see this:
Somehow, the player sprite is drawn in the new position but the view did not get updated.
4) Immediately after 3, the view is corrected and it looks normal again
Also, yes, I am no artist and these images are placeholders. Don't laugh.
Any idea what might be causing this?
Thanks
Edit: I can see the images are a bit bigger than the space allows here, might be easier if they're viewed somewhere else. Here's the link to the album:
http://imgur.com/156ASOz,ULuVyvH,aPTNJaT,9HiJv4S#0