Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
animator.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <vector>
8
22class Animator : public Component {
23 private:
24 std::vector<std::reference_wrapper<Texture>> frames_;
25 const int interval_ms_;
26
27 int current_texture_index_;
28 int accumulator_time_ms_;
29
30 bool is_playing_;
31 bool is_looping_;
32 bool is_non_interruptible_{false};
33
34 [[nodiscard]] int calculate_next_frame_index(int intervals_advanced) const;
35 void update_sprite_texture(int new_frame_index);
36
37 public:
38 explicit Animator(const std::string& sprite_sheet_name, int interval_ms);
39
40 void play(bool is_looping);
41 void play(const std::string& animation_name, bool is_looping);
42
43 void pause();
44 void reset();
45 [[nodiscard]] bool is_playing() const noexcept;
46
47 [[nodiscard]] bool is_non_interruptible() const noexcept;
48 void is_non_interruptible(bool value) noexcept;
49
50 // Component overrides
51 void update(float dt_seconds) override;
52
53 void set_animation(const std::string& animation_name);
55 const std::vector<std::reference_wrapper<Texture>>& frames_);
56
57 std::string type_name() const override;
58};
Component that handles sprite sheet animations.
Definition animator.h:22
void reset()
void update(float dt_seconds) override
void pause()
Animator(const std::string &sprite_sheet_name, int interval_ms)
std::string type_name() const override
Provides a consistent type name for the component.
void play(const std::string &animation_name, bool is_looping)
void set_animation(const std::string &animation_name)
void play(bool is_looping)
bool is_playing() const noexcept
bool is_non_interruptible() const noexcept
Base class for all components that can be attached to GameObjects.
Definition component.h:24
Represents a texture used in rendering game objects. Encapsulates an SDL_Texture and provides access ...
Definition texture.h:10