Hi , I am trying to learn SFML, but all I've done is a skeleton of a game.
1. I created a sprite and added it to window.
2. I create a map(tiled map) and added it, too.
But, when i move my sprite it is very slow and has a lot of lags, i don't now why...or i do, I think this is caused because I draw my map and sprite always after moving sprite. How can I change this thing? 'cause if I remove draw.map, the sprite is very smooth and fast.
This is a part of my code :
while (window.isOpen()){
// handle events
sf::Event event;
while (window.pollEvent(event)){
if (event.type == sf::Event::Closed)
window.close();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Up)) {
x = 68;
player.move(0.0, -20.0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Down)) {
x = 0;
player.move(0.0, 20.0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left)) {
x = 3 * 70;
player.move(-20.0, 0.0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right)) {
x = 2 * 68;
player.move(20.0, 0.0);
}
//texture.loadFromFile("tank.png", sf::IntRect(x, 0, 80, 65));
//changed to
player.setTextureRect(sf::IntRect(x, 0, 79, 63));
window.clear();
window.draw(map);
window.draw(player);
window.display();
}