21 #include "hx3d/graphics/texture_atlas.hpp" 23 #include "hx3d/utils/log.hpp" 24 #include "hx3d/graphics/texture.hpp" 26 #include <rapidjson/document.h> 32 loadFromJSON(pathToAtlas);
36 return _regions[name];
39 void TextureAtlas::loadFromJSON(std::string pathToAtlas) {
41 std::string content = file->toString();
43 rapidjson::Document d;
44 d.Parse(content.c_str());
46 std::string image = d[
"image"].GetString();
47 std::string type = d[
"type"].GetString();
49 Log.
Info(
"Loading texture atlas `%s`...", pathToAtlas.c_str());
50 Log.
Info(
"\tImage: %s", image.c_str());
51 Log.
Info(
"\tType: %s", type ==
"pure" ?
"Pure" :
"Animated");
54 _texture = Make<Texture>(image);
56 const rapidjson::Value& frames = d[
"frames"];
57 for (
auto it = frames.Begin(); it != frames.End(); ++it) {
58 const rapidjson::Value& val = *it;
59 std::string name = val[
"name"].GetString();
60 int x = std::atoi(val[
"x"].GetString());
61 int y = std::atoi(val[
"y"].GetString());
62 int w = std::atoi(val[
"w"].GetString());
63 int h = std::atoi(val[
"h"].GetString());
73 _regions.emplace(std::make_pair(name, region));
77 Log.
Error(
"/!\\ Animated atlas not supported yet.");
TextureAtlas(std::string pathToAtlas)
Load an atlas from a path.
static Ptr< File > loadAsciiFile(std::string path)
Load an ascii file from a path.
TextureRegion & getRegion(std::string name)
Get a region following a name.
void Error(const std::string fmt,...)
Write an error message.
Defines a rectangle in a texture.
static hx3d::LogImpl Log
Current log implementation.
void Info(const std::string fmt,...)
Write an info message.