Created
October 20, 2012 00:08
-
-
Save micahrj/3921383 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// image_manager.hpp | |
#ifndef IMAGE_MANAGER_HPP | |
#define IMAGE_MANAGER_HPP | |
#include <SFML/System.hpp> | |
#include <SFML/Graphics.hpp> | |
#include <map> | |
using namespace sf; | |
class ImageManager { | |
public: | |
static Texture getTexture(String path, IntRect = IntRect(0, 0, 0, 0), int frame = 0); | |
static std::map<String, Texture> textures; | |
}; | |
#endif | |
// image_manager.cpp | |
#include "image_manager.hpp" | |
#include <map> | |
Texture ImageManager::getTexture(String path, IntRect size, int frame) { | |
if (textures.count(path)) { | |
return textures[path]; | |
} else { | |
textures[path] = Texture(); | |
textures[path].loadFromFile(path); | |
return textures[path]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ImageManager::getTexture should return Texture&, since sf::Textures are expensive to copy and most of the time you probably only want to bind a texture to an sf::Sprite.