fix animation manager

This commit is contained in:
Alfie King 2024-09-06 11:52:36 +01:00
parent 8091651cc7
commit 5813da7e97
5 changed files with 13 additions and 10 deletions

View File

@ -49,7 +49,7 @@ class Animation
class AnimationManager class AnimationManager
{ {
private: private:
std::map<std::string, Animation> *animations; std::map<std::string, Animation*> animations;
std::map<std::string, bool> flip; std::map<std::string, bool> flip;
std::map<std::string, bool> autoRect; std::map<std::string, bool> autoRect;
std::string currentAnimation; std::string currentAnimation;

View File

@ -14,4 +14,4 @@ private:
public: public:
Text(TTF_Font* font, SDL_Color color); Text(TTF_Font* font, SDL_Color color);
void draw(SDL_Renderer* renderer, std::string text, int x, int y); void draw(SDL_Renderer* renderer, std::string text, int x, int y);
}; };

View File

@ -13,5 +13,8 @@ $(TARGET): $(OBJ)
build/%.o: src/%.cpp build/%.o: src/%.cpp
@$(CXX) -c -o $@ $< $(CXXFLAGS) @$(CXX) -c -o $@ $< $(CXXFLAGS)
dirs:
@mkdir -p build/x86_64
clean: clean:
@rm -f $(OBJ) $(TARGET) @rm -f $(OBJ) $(TARGET)

View File

@ -54,7 +54,7 @@ int main(int argc, char* argv[])
// Create sprite and animation // Create sprite and animation
Sprite* sprite = new Sprite(renderer, assets); Sprite* sprite = new Sprite(renderer, assets);
AnimationManager* animations = new AnimationManager(sprite); AnimationManager* animations = new AnimationManager(sprite);
animations->addAnimation("idle", frames); animations->addAnimation("idle", frames, 10, false, true, true, true);
animations->setAnimation("idle"); animations->setAnimation("idle");
// Main loop // Main loop
@ -76,8 +76,8 @@ int main(int argc, char* argv[])
animations->update(); animations->update();
// Clear screen // Clear screen
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); SDL_SetRenderDrawColor(renderer, 100, 100, 255, 255);
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
// Draw sprite // Draw sprite
animations->draw(renderer); animations->draw(renderer);

View File

@ -106,10 +106,10 @@ void AnimationManager::addAnimation(std::string name, std::map<std::string, SDL_
animations[name] = new Animation(frames, sprite, frameDuration); animations[name] = new Animation(frames, sprite, frameDuration);
this->flip[name] = flip; this->flip[name] = flip;
this->autoRect[name] = autoRect; this->autoRect[name] = autoRect;
animations[name].loop = loop; animations[name]->loop = loop;
animations[name].pingpong = pingpong; animations[name]->pingpong = pingpong;
} }
void autorect(std::string frame);
void AnimationManager::setAnimation(std::string name) void AnimationManager::setAnimation(std::string name)
{ {
currentAnimation = name; currentAnimation = name;
@ -117,10 +117,10 @@ void AnimationManager::setAnimation(std::string name)
void AnimationManager::update() void AnimationManager::update()
{ {
animations[currentAnimation].update(); animations[currentAnimation]->update();
} }
void AnimationManager::draw(SDL_Renderer* renderer) void AnimationManager::draw(SDL_Renderer* renderer)
{ {
animations[currentAnimation].draw(renderer, autoRect[currentAnimation], flip[currentAnimation]); animations[currentAnimation]->draw(renderer, autoRect[currentAnimation], flip[currentAnimation]);
} }