23#define __WIZARD_ENGINE_INTERNAL__
28wze::animator::animator(
29 std::vector<std::pair<std::shared_ptr<texture>, uint16_t>>
const& frames,
30 std::vector<std::weak_ptr<animatable>>
const& targets) {
31 this->frames() = frames;
32 this->targets() = targets;
37std::vector<std::pair<std::shared_ptr<wze::texture>, uint16_t>>
const&
38wze::animator::frames()
const {
42std::vector<std::pair<std::shared_ptr<wze::texture>, uint16_t>>&
43wze::animator::frames() {
47std::vector<std::weak_ptr<wze::animatable>>
const&
48wze::animator::targets()
const {
52std::vector<std::weak_ptr<wze::animatable>>& wze::animator::targets() {
56size_t wze::animator::current_frame()
const {
57 return _current_frame;
60void wze::animator::set_current_frame(
size_t current_frame) {
61 _current_frame = current_frame;
64bool wze::animator::play() {
65 uint32_t elapsed_time;
68 if (frames().empty()) {
72 if ((
bool)frames().at(current_frame()).second) {
74 set_current_frame(current_frame() +
75 elapsed_time / frames().at(current_frame()).second);
76 _remaining_time = elapsed_time % frames().at(current_frame()).second;
78 set_current_frame(current_frame() + 1);
82 looped = frames().size() <= current_frame();
84 set_current_frame(current_frame() % frames().size());
88 std::remove_if(targets().begin(), targets().end(),
89 [&](std::weak_ptr<animatable>
const& target) ->
bool {
90 std::shared_ptr<animatable> locked;
92 locked = target.lock();
94 if (locked->animated()) {
96 frames().at(current_frame()).first);
108void wze::animator::reset() {
109 set_current_frame(0);
Animates animatable objects.
static float delta_time()
Gets the current delta time in milliseconds.