From 5813da7e97ebe43885ef29393722f4bdf58a7b51 Mon Sep 17 00:00:00 2001 From: Alfie King Date: Fri, 6 Sep 2024 11:52:36 +0100 Subject: [PATCH] fix animation manager --- include/sprite.h | 2 +- include/text.h | 2 +- makefile | 3 +++ src/main.cpp | 6 +++--- src/sprite.cpp | 10 +++++----- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/include/sprite.h b/include/sprite.h index d0b3f5b..990303e 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -49,7 +49,7 @@ class Animation class AnimationManager { private: - std::map *animations; + std::map animations; std::map flip; std::map autoRect; std::string currentAnimation; diff --git a/include/text.h b/include/text.h index 33f3fe9..815c1b7 100644 --- a/include/text.h +++ b/include/text.h @@ -14,4 +14,4 @@ private: public: Text(TTF_Font* font, SDL_Color color); void draw(SDL_Renderer* renderer, std::string text, int x, int y); -}; +}; \ No newline at end of file diff --git a/makefile b/makefile index 7f45a21..6d6b96e 100644 --- a/makefile +++ b/makefile @@ -13,5 +13,8 @@ $(TARGET): $(OBJ) build/%.o: src/%.cpp @$(CXX) -c -o $@ $< $(CXXFLAGS) +dirs: + @mkdir -p build/x86_64 + clean: @rm -f $(OBJ) $(TARGET) \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 4b5c26d..77e4e7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,7 @@ int main(int argc, char* argv[]) // Create sprite and animation Sprite* sprite = new Sprite(renderer, assets); AnimationManager* animations = new AnimationManager(sprite); - animations->addAnimation("idle", frames); + animations->addAnimation("idle", frames, 10, false, true, true, true); animations->setAnimation("idle"); // Main loop @@ -76,8 +76,8 @@ int main(int argc, char* argv[]) animations->update(); // Clear screen - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); - SDL_RenderClear(renderer); + SDL_SetRenderDrawColor(renderer, 100, 100, 255, 255); + SDL_RenderClear(renderer); // Draw sprite animations->draw(renderer); diff --git a/src/sprite.cpp b/src/sprite.cpp index 87be1c0..8415f9e 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp @@ -106,10 +106,10 @@ void AnimationManager::addAnimation(std::string name, std::mapflip[name] = flip; this->autoRect[name] = autoRect; - animations[name].loop = loop; - animations[name].pingpong = pingpong; + animations[name]->loop = loop; + animations[name]->pingpong = pingpong; } - + void autorect(std::string frame); void AnimationManager::setAnimation(std::string name) { currentAnimation = name; @@ -117,10 +117,10 @@ void AnimationManager::setAnimation(std::string name) void AnimationManager::update() { - animations[currentAnimation].update(); + animations[currentAnimation]->update(); } void AnimationManager::draw(SDL_Renderer* renderer) { - animations[currentAnimation].draw(renderer, autoRect[currentAnimation], flip[currentAnimation]); + animations[currentAnimation]->draw(renderer, autoRect[currentAnimation], flip[currentAnimation]); } \ No newline at end of file