MCPcopy Create free account
hub / github.com/AbyssEngine/AbyssEngineOld / Animation

Class Animation

src/Abyss/Common/Animation.h:14–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12inline constexpr float AnimationSpeedUnit = AnimationFPS * AnimationDivisor;
13
14template <Concepts::Drawable T> class Animation {
15 T _drawable;
16 double _frameTime;
17 uint32_t _frameIdx;
18 double _animationSpeed;
19
20 public:
21 explicit Animation(std::string_view path) : _drawable(path), _frameTime(), _frameIdx(), _animationSpeed(0.5 * (AnimationSpeedUnit)) {}
22 void draw(int x, int y) { _drawable.draw(_frameIdx, x, y); }
23
24 void update(const std::chrono::duration<double> deltaTime) {
25 _frameTime += deltaTime.count();
26 const auto framesToAdd = static_cast<uint32_t>(_frameTime / _animationSpeed);
27 _frameTime -= framesToAdd * _animationSpeed;
28 _frameIdx += framesToAdd;
29 _frameIdx %= _drawable.getFrameCount();
30 }
31
32 void setPalette(const Abyss::DataTypes::Palette &palette) { _drawable.setPalette(palette); }
33
34 void setBlendMode(Enums::BlendMode blendMode) { _drawable.setBlendMode(blendMode); }
35};
36
37} // namespace Abyss::Common

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected