I want to have an array of sf::Texture's(sfml) in a class, and then want to have a function that returns a pointer to that specific item in the array(vector). I then want to pass that to sprite.SetTexture(also SFML) which requires a sf::texture. But I can't get it to work, this is what I currently have, I left unimportant things out:
class SpriteTextures
{
public:
std::vector<sf::Texture> Textures;
//code to fill the vector here
sf::Texture *GetSecondTexture()
{
return &Textures[1];
}
};
class DrawSprite
{
sf::Texture *texture;
sf::Sprite sprite;
public:
void SetSpriteTexture()
{
SpriteTextures SprTexs;
texture = SprTexs.GetSecondTexture();
sprite.setTexture(texture, true); // Gives error about no suitable constructor exists to convert from sf::Texture * to sf::Texture
// do some other stuff with the texture here.
}
};
and this is the function defenition of Sprite::setTexture:
void setTexture(const Texture& texture, bool resetRect = false);
And the error it gives i have put as a comment in the code(next to the setTexture function) So what I want is, that instead of making a copy of the vector item to the texture var in the DrawSprite class, I want the *texture in DrawSprite to point to the item in the vector. But I do want to set the *texture in DrawSprite first as i want to use it for other things too. So i want to be able to supply the setTexture function with my *texture, and have it read the sf::Texture in the vector in SpriteTextures class.(Instead of reading a copy of it in the texture variable in the DrawSprite class itself.
SO if someone understands what I just said, can someone help me getting it work correctly?
Thanks!