So I have this class and it wants to be able to store the texture of a sprite, change the texture, and then when the object passes out of scope, change the texture back to the original. The problem I'm having is that I can't find a way to store the original texture.
Details
=====
- Using dynamic SFML 2.4.2
- Using Visual Studio 2015 community
Here is the header file:
#pragma once
#include "game.h"
using namespace sf;
const Vector2f DEFUALT_START_POSISTION = Vector2f(800, 450);
class Battle {
public:
Battle(Sprite& controlledCharacter, float playerXNew, float playerYNew, float cameraXNew, float cameraYNew, Texture& area);
~Battle();
float m_playerXInit;
float m_playerYInit;
float m_cameraXInit;
float m_cameraYInit;
Sprite m_controlledCharacter;
Texture m_area;
Texture m_backgroundInit;
};
Here is the .cpp:
#include "Battle.h"
using namespace sf;
Battle::Battle(Sprite& controlledCharacter, float playerXNew, float playerYNew, float cameraXNew, float cameraYNew, Texture& area)
: m_controlledCharacter(controlledCharacter), m_area(area)
{
m_playerXInit = controlledCharacter.getPosition().x;
m_playerYInit = controlledCharacter.getPosition().y;
m_cameraXInit = viewBox.getCenter().x;
m_cameraYInit = viewBox.getCenter().y;
Texture m_backgroundInit = Background.getTexture();
controlledCharacter.setPosition(Vector2f(playerXNew, playerYNew));
viewBox.setCenter(Vector2f(cameraXNew, cameraYNew));
Background.setTexture(area);
}
Battle::~Battle() {
m_controlledCharacter.setPosition(Vector2f(m_playerXInit, m_playerYInit));
viewBox.setCenter(Vector2f(m_cameraXInit, m_cameraYInit));
Background.setTexture(m_backgroundInit);
}
The line "Texture m_backgroundInit = Background.getTexture();" has the problem:"No suitable constructor exists to convert from 'const sf::Texture' to 'sf::Texture'"
How can I store the texture info?