'Why is it skipping Sprite.setTexture()?
I have been trying to run my code and it has been skipping this line
this->tileSprite.setTexture(this->tileTexture);
within the constructor of my class Tile
Tile::Tile()
{
int RNG = rand() % 3 + 1; // randomizer for texture loading
this->pX = this->pY = 0;
if (RNG == 1)
{
// loads pattern 1
this->tileTexture.loadFromFile("Sprites/Ground/Unrevealed/Unrevealed Tile 1.png");
this->tileSprite.setTexture(this->tileTexture);
}
else if (RNG == 2)
{
// loads pattern 2
this->tileTexture.loadFromFile("Sprites/Ground/Unrevealed/Unrevealed Tile 2.png");
this->tileSprite.setTexture(this->tileTexture);
}
else if (RNG == 3)
{
// loads pattern 3
this->tileTexture.loadFromFile("Sprites/Ground/Unrevealed/Unrevealed Tile 3.png");
this->tileSprite.setTexture(this->tileTexture);
}
}
Here's also my Tile class
class Tile
{
public:
// constructors
Tile();
~Tile();
// getters
// data getters
float getX();
float getY();
sf::Sprite getSprite();
// list getters
Tile* getNext();
Tile* getPrev();
int getListpos();
//tile getters
Tile* getLf();
Tile* getRt();
Tile* getUp();
Tile* getDn();
Tile* getClu();
Tile* getCld();
Tile* getCru();
Tile* getCrd();
//setters
// data setters
void setX(float newX);
void setY(float newY);
virtual void setSprite(sf::Texture& newTexture);
void setSpritePos(float xPos, float yPos);
// list setters
void setNext(Tile* nextTile);
void setPrev(Tile* prevTile);
void setListpos(int Listpos);
//tile setters
void setLf(Tile* newLf);
void setRt(Tile* newRt);
void setUp(Tile* newUp);
void setDn(Tile* newDn);
void setClu(Tile* newClu);
void setCld(Tile* newCld);
void setCru(Tile* newCru);
void setCrd(Tile* newCrd);
//other functions
private:
// data of the node
float pX;
float pY;
sf::Sprite tileSprite;
sf::Texture tileTexture;
// postions of list
Tile* tNext;
Tile* tPrev;
int Listpos;
// postions of Tile
Tile* Lf; // Left of the tile
Tile* Rt; // right of the tile
Tile* Up; // Up of the tile
Tile* Dn; // down of the tile
Tile* Clu; // conner left up of the tile
Tile* Cld; // conner left down of the tile
Tile* Cru; // conner right up of the tile
Tile* Crd; // conner right down of the tile
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|