//Ground.h klasa
#include "headers.h"
class Ground {
public:
const std::string GROUND_TEXTURE_PATH = "Ground.png";
void setWidth(int inWidth); //ustaw wysokość
void setHeight(int inHeight); //ustaw szerokosc
void printGround(int inWidth, int inHeight, std::string inTexture);
sf::RectangleShape rectangle;
private:
//tekstura
sf::Texture texture;
//shape
int width = 600;
int height = 800;
void loadTexture(std::string path); //pobierz i ustaw teksture
void setSquareGround(); //stworz ksztalt i ustaw teksture
};
#include "headers.h"
#include "Ground.h"
void Ground::loadTexture(std::string path) {
sf::Texture texture;
texture.create(this->width, this->height);
if(!texture.loadFromFile(path)) {
std::cout<<"file not found";
}
else
std::cout<<1;
}
void Ground::setWidth(int inWidth){
this->width=inWidth;
}
void Ground::setHeight(int inHeight){
this->height=inHeight;
}
void Ground::setSquareGround() {
this->rectangle.setSize(sf::Vector2f(this->height, this->width));
this->rectangle.setTexture(&this->texture);
//this->rectangle.setTextureRect(sf::IntRect(10, 10, 100, 100));
}
void Ground::printGround(int inWidth, int inHeight, std::string inTexture) {
loadTexture(inTexture);
setWidth(inWidth);
setHeight(inHeight);
setSquareGround();
}
main:
Ground floor;
floor.printGround(600, 800, "Ground.png");
window.draw(floor.rectangle);
window.display();
Nadal shape wyświetla się bez tekstury. Co robię nie tak :/