| 27 | void SpriteAtlas::initialize(unsigned int* ptex) { texture = ptex; } |
| 28 | |
| 29 | void SpriteAtlas::loadFromFile(const char* filename) |
| 30 | { |
| 31 | string line; |
| 32 | ifstream file(resolveResourcePath(filename)); |
| 33 | istringstream ssf; |
| 34 | int delay; |
| 35 | int index; |
| 36 | ScreenRect srcRect; |
| 37 | |
| 38 | if (file.is_open()) |
| 39 | { |
| 40 | getline(file, line); |
| 41 | if (line.compare(0, 3, "\xEF\xBB\xBF") == 0) |
| 42 | line.erase(0, 3); |
| 43 | ssf = istringstream(line); |
| 44 | ssf >> imageSize.x >> imageSize.y; |
| 45 | while (getline(file, line)) |
| 46 | { |
| 47 | ssf = istringstream(line); |
| 48 | ssf >> index; |
| 49 | if (index != -1) |
| 50 | { |
| 51 | while (getline(file, line)) |
| 52 | { |
| 53 | ssf = istringstream(line); |
| 54 | ssf >> delay >> srcRect.x >> srcRect.y >> srcRect.w >> |
| 55 | srcRect.h; |
| 56 | if (delay == -1) |
| 57 | break; |
| 58 | else |
| 59 | { |
| 60 | srcRect.w = srcRect.w / imageSize.x; |
| 61 | srcRect.h = -srcRect.h / imageSize.y; |
| 62 | srcRect.x = srcRect.x / imageSize.x; |
| 63 | srcRect.y = 1.0 - srcRect.y / imageSize.y; |
| 64 | addFrame(index, srcRect, delay); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | file.close(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | void SpriteAtlas::addFrame(unsigned int index, ScreenRect src_rect, |
| 74 | unsigned int delay) |
no test coverage detected