Voici mon code :
//class/header.h
#ifndef HEADER_H
#define HEADER_H
#include <string>
#include <SFML/Graphics.hpp>
class player{
private:
sf::Texture texture;
public:
sf::Sprite sprite;
void setTexture(std::string tex);
};
#endif//HEADER_H
//class/header.cpp
#include <SFML/Graphics.hpp>
#include "header.h"
void player::setTexture(std::string tex){
player::texture.loadFromFile(tex);
player::texture.setSmooth(true);
player::sprite.setTexture(player::texture);
}
//main.cpp
#include <SFML/Graphics.hpp>
#include <iostream>
#include "class/header.h"
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();
}