Ton code (corrigé et complété) fonctionne très bien chez moi.
#include <string>
#include <SFML/Graphics.hpp>
class player{
private:
sf::Texture texture;
public:
sf::Sprite sprite;
void setTexture(std::string tex);
};
void player::setTexture(std::string tex){
player::texture.loadFromFile(tex);
player::texture.setSmooth(true);
player::sprite.setTexture(player::texture);
}
#include <iostream>
int main()
{
sf::RenderWindow window;
player p1;
std::cout << "Game started !"<<std::endl;
window.create(sf::VideoMode(1280, 720), "Arpg", sf::Style::Close | sf::Style::Titlebar);
window.setPosition(sf::Vector2i(175,75));
window.setFramerateLimit(60);
p1.setTexture("sprites/player.png");
p1.sprite.setPosition(50.0f, 50.0f);
while(window.isOpen())
{
sf::Event envent;
while(window.pollEvent(envent))
{
if(envent.type == sf::Event::Closed)
{
window.close();
}
}
p1.sprite.move(1, 0);
std::cout << p1.sprite.getPosition().x << ", " << p1.sprite.getPosition().y <<std::endl;
window.draw(p1.sprite);
window.display();
window.clear();
}
return 0;
}