/* * 2D Game Engine * Animation.h: * Based on pikuma.com 2D game engine in C++ and Lua course * Copyright (c) 2021 986-Studio. All rights reserved. * * Created by Manoƫl Trapier on 15/02/2021. */ #ifndef GAMEENGINE_ANIMATIONSYS_H #define GAMEENGINE_ANIMATIONSYS_H #include #include #include class AnimationSystem: public System { public: AnimationSystem() { this->requireComponent(); this->requireComponent(); } void update() { for(auto entity: this->getSystemEntities()) { auto &animation = entity.getComponent(); auto &sprite = entity.getComponent(); animation.currentFrame = ((SDL_GetTicks() - animation.startTime) * animation.frameSpeedRate / 1000) % animation.numFrames; sprite.sourceRect.x = animation.currentFrame * sprite.width; } } }; #endif /* GAMEENGINE_ANIMATIONSYS_H */