From 908f792db6fdc04fde4b48e8873767edd5d59cea Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 31 Jan 2021 12:08:02 -0500 Subject: Made use of new sprite sheet data! --- src/sprite.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'src/sprite.cpp') diff --git a/src/sprite.cpp b/src/sprite.cpp index c52807a..b84f4ce 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp @@ -12,14 +12,53 @@ Sprite::Sprite(std::string_view filename, Renderer& renderer) { } char ch; + std::string line; std::string imagename; datafile >> imagename; textureId_ = renderer.loadImageFromFile(imagename); - datafile >> size_.w(); - datafile >> ch; //, - datafile >> size_.h(); + std::string framefilename; + datafile >> framefilename; + + std::ifstream framefile(framefilename); + if (!framefile.is_open()) { + throw std::invalid_argument("Could not find frame datafile: " + framefilename); + } + + vec2i cellSize; + framefile >> cellSize.w(); + framefile >> ch; //, + framefile >> cellSize.h(); + std::getline(framefile, line); // cell size + + int framesPerRow; + framefile >> framesPerRow; + std::getline(framefile, line); // frames per row + + int numFrames; + framefile >> numFrames; + std::getline(framefile, line); // frames + std::getline(framefile, line); // blank + + for (int i=0; i> f.size.w(); + framefile >> ch; //, + framefile >> f.size.h(); + framefile >> ch; //, + framefile >> f.center.x(); + framefile >> ch; //, + framefile >> f.center.y(); + std::getline(framefile, line); // blank + + f.srcRect.x = (i % framesPerRow) * cellSize.w(); + f.srcRect.y = (i / framesPerRow) * cellSize.h(); + f.srcRect.w = f.size.w(); + f.srcRect.h = f.size.h(); + + frames_.push_back(std::move(f)); + } std::string animLine; std::getline(datafile, animLine); // blank -- cgit 1.4.1