12345678910111213141516171819202122232425262728293031323334353637383940 |
- /*
- * 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 <ECS.h>
- #include <Components/Animation.h>
- #include <Components/Sprite.h>
- class AnimationSystem: public System
- {
- public:
- AnimationSystem()
- {
- this->requireComponent<AnimationComponent>();
- this->requireComponent<SpriteComponent>();
- }
- void update()
- {
- for(auto entity: this->getSystemEntities())
- {
- auto &animation = entity.getComponent<AnimationComponent>();
- auto &sprite = entity.getComponent<SpriteComponent>();
- animation.currentFrame = ((SDL_GetTicks() - animation.startTime) * animation.frameSpeedRate / 1000) % animation.numFrames;
- sprite.sourceRect.x = animation.currentFrame * sprite.width;
- }
- }
- };
- #endif /* GAMEENGINE_ANIMATIONSYS_H */
|