Hello, I'm new to both SFML and this forum. I started learning SFML today so i decided to try implement some of the things I learned. Everything was fine until I used the .move function. Everything draws and runs but when the sprite moves it doesn't get rid of the previous state of the sprite, but keeps the drawn sprite.
My code:
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!", sf::Style::Fullscreen);
float x1 = 0;
float y1 = 725;
int x = 0;
int y = 800;
window.setVerticalSyncEnabled(true);
window.clear(sf::Color::Black);
sf::Texture texture;
if(!texture.loadFromFile("sprite.png", sf::IntRect(0,0,75,200))){
std::cout<< "The sprite could not be loaded."<<std::endl;
}
sf::Texture sprite1;
if(!sprite1.loadFromFile("Sprite2.png", sf::IntRect(140,110,80,80))){
std::cout<<"Could not load texture."<<std::endl;
}
sf::Sprite sprites;
sprites.setTexture(sprite1);
sprites.setPosition(x1,y1);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::KeyPressed){
if(event.key.code == sf::Keyboard::Escape){
window.close();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
sprites.move(5,0);
}
}
}
window.draw(sprites);
sf::Sprite sprite;
sprite.setTexture(texture);
while( x < 1600){
sprite.setPosition(sf::Vector2f(x,y));
window.draw(sprite);
x = x + 75;
}
window.display();
}
return 0;
}
Sorry if it is messy, or unprofessional. I just really want to learn how to do this. Thank you!