Hello
can you tell me what's wrong with this code? When I move the character in any direction, it is displayed twice. There is like a transparent remnant of the sprite.
It does not appear on screenshot so I took a picture instead
If I remove the setVerticalSync it will be smooth, but from time to time the remnant will appear for like a fraction of second.
It seems to be caused by the view. Before using one, movements were smooth.
#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(640, 480), "Test");
window.setMouseCursorVisible(false);
window.setVerticalSyncEnabled(true);
sf::View view = window.getView();
sf::Texture texCharacter;
if (!texCharacter.loadFromFile("character.png"))
return -1;
sf::Sprite character;
character.setTexture(texCharacter);
sf::Texture texMap;
if (!texMap.loadFromFile("map.png"))
return -1;
sf::Sprite map;
map.setTexture(texMap);
map.setPosition(sf::Vector2f(-640, -480));
sf::Music music;
if (!music.openFromFile("music.ogg"))
return -1;
sf::SoundBuffer buffer;
if (!buffer.loadFromFile("sound.wav"))
return -1;
sf::Sound sound;
sound.setBuffer(buffer);
music.play();
music.setLoop(true);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl))
sound.play();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
character.move(-32, 0);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
character.move(+32, 0);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
character.move(0, -32);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
character.move(0, +32);
}
window.clear();
window.draw(map);
window.draw(character);
view.setCenter(character.getPosition());
window.setView(view);
window.display();
}
return 0;
}
Thanks for your help.