Skip to content

Instantly share code, notes, and snippets.

@micahrj
Created October 20, 2012 00:08
Show Gist options
  • Save micahrj/3921383 to your computer and use it in GitHub Desktop.
Save micahrj/3921383 to your computer and use it in GitHub Desktop.
// 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];
}
}
@elliothatch
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment