So when i store sprite to map and get it back, texture disappears. Can someone tell me why is that happening
.
Sprite.cpp:
#include <SFML\Graphics.hpp>
std::map<std::string, sf::Sprite> sprites;
void addSprite(std::string sprite_name, sf::Texture sprite_texture) {
sf::Sprite sprite;
sprite.setTexture(sprite_texture);
sprites[sprite_name] = sprite;
}
sf::Sprite getSprite(std::string sprite_name) {
sf::Sprite sprite = sprites[sprite_name];
return sprite;
}
Game.cpp:
#include <iostream>
#include "Game.h"
#include "Window.h"
#include <thread>
#include "Resource.h"
#include "Sprite.h"
bool game_running = STOP;
void createGame() {
openWindow();
loadResources();
startGame();
}
void loadResources() {
//player
sf::Texture player_texture = loadTexture("C:/Users/User/Desktop/resources/player_texture.png");
addSprite("player_sprite", player_texture);
}
Window.cpp:
#include <SFML\Graphics.hpp>
#include <thread>
#include "Game.h"
#include "Resource.h"
#include "Sprite.h"
sf::RenderWindow window;
void openWindow() {
window.create(sf::VideoMode(800, 600), getGameName());
window.setVerticalSyncEnabled(true);
sf::Sprite sprite_test = getSprite("player_sprite"); //there is no error here
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
window.close();
break;
}
}
window.clear();
window.draw(sprite_test); //and when i draw it nothing happens. There is even no white texture.
window.display();
}
}
I hope someone can help me, because i'm messing with this whole 2 days...