So, im trying to create a pacman game in SFML, i created a class named fant for my ghosts,
im trying to pass a sf::Image has a parameter in my class, but it seems that I got a variable without a value, cause it load a blank image, but it has the same size (18×18 pixels) of the image im trying to load.
My class is
class fant {
public:
void SetX(int i);
int GetX();
void SetY(int i);
int GetY();
void SetDX(int i);
int GetDX();
void SetDY(int i);
int GetDY();
void Sprite(sf::Sprite i);
sf::Sprite GetSprite();
void Image(sf::Image i);
protected:
int posx,posy,dirx,diry;
sf::Sprite sprite;
};
void fant::SetX(int i) { posx=i; sprite.SetX(posx); }
void fant::SetY(int i) { posy=i; sprite.SetY(posy); }
void fant::SetDX(int i) { dirx=i; }
void fant::SetDY(int i) { diry=i; }
void fant::Sprite(sf::Sprite i) { sprite=i; }
void fant::Image(sf::Image i) { sprite.SetImage(i); }
sf::Sprite fant::GetSprite() { return sprite; }
int fant::GetX() { return posx; }
int fant::GetY() { return posy; }
int fant::GetDX() { return dirx; }
int fant::GetDY() { return diry; }
and thats a function that create a new object
void addf() {
fa.push_back(fant());
int t=fa.size()-1;
fa[t].SetX(684); fa[t].SetY(18);
fa[t].Image(f1);
fa[t].SetDX(6);
fa[t].SetDY(0);
}
If i use
void fant::Image(sf::Image i) { sprite.SetImage(f1); }
it sets the “f1” image. (a global sf::Image)
and