TazGraph Project v0.1.0
Loading...
Searching...
No Matches
RectangleFlashAnimatorComponent.h
1#pragma once
2
3
4#include "../../Components.h"
5#include <map>
6#include "../Animation.h"
7#include "../AnimatorManager.h"
8
9
10typedef uint32_t timestamp;
11
12
13class RectangleFlashAnimatorComponent : public Component //Animator -> Sprite -> Transform
14{
15public:
16
18 std::string animationName = "";
19 timestamp resumeTime = 0;
20
22 {
23
24 }
25
27 {
28
29 }
30
31 void init() override
32 {
33 if (!entity->hasComponent<Rectangle_w_Color>())
34 {
36 }
37 rectangle = &entity->GetComponent<Rectangle_w_Color>();
38
39 Play("Default");
40 }
41
42 void update(float deltaTime) override
43 {
44 if (animationName == "Default") {
45 return;
46 }
47 if (rectangle->flash_animation.hasFinished()) { // playing again animation
48 rectangle->flash_animation.finished = false;
49 rectangle->flash_animation.times_played = 0;
50 resetAnimation();
51 }
52
53 rectangle->flash_animation.advanceFrame(deltaTime);
54 rectangle->setFlashFrame();
55 }
56
57 void draw(size_t e_index, PlaneModelRenderer& batch, TazGraphEngine::Window& window) override
58 {
59 //sprite->draw(batch);
60 }
61
62 void Play(const std::string& animName, int reps = 0)
63 {
64 AnimatorManager& animManager = AnimatorManager::getInstance();
65 animationName = animName;
66 FlashAnimation& flash_animation = animManager.flash_animations[animationName];
67 rectangle->SetFlashAnimation(
68 flash_animation.total_frames, flash_animation.speed,
69 flash_animation.type,
70 flash_animation.getSpeedsAsVector(),
71 flash_animation.flashColor,
72 reps ? reps : flash_animation.reps
73 );
74 }
75
76 void Play(const std::string& animName, TazColor m_destColor, int reps = 0)
77 {
78 AnimatorManager& animManager = AnimatorManager::getInstance();
79 animationName = animName;
80 FlashAnimation& flash_animation = animManager.flash_animations[animationName];
81 rectangle->SetFlashAnimation(
82 flash_animation.total_frames, flash_animation.speed,
83 flash_animation.type,
84 flash_animation.getSpeedsAsVector(),
85 m_destColor,
86 reps ? reps : flash_animation.reps
87 );
88 }
89
90 void resetAnimation() {
91 rectangle->default_color = rectangle->color;
92
93 AnimatorManager& animManager = AnimatorManager::getInstance();
94 animationName = "Default";
95 rectangle->SetFlashAnimation(
96 animManager.flash_animations[animationName].total_frames, animManager.flash_animations[animationName].speed,
97 animManager.flash_animations[animationName].type,
98 animManager.flash_animations[animationName].getSpeedsAsVector(),
99 animManager.flash_animations[animationName].flashColor);
100 }
101
102 std::string getPlayName()
103 {
104 return animationName;
105 }
106
107};
Definition GECS.h:131
T & addComponent(TArgs &&... mArgs)
have addScript function
Definition GECS.h:345
Definition PlaneModelRenderer.h:15
Definition RectangleFlashAnimatorComponent.h:14
Rectangle_w_Color * rectangle
also we use MovingAnimator instead of simple Animator so that entities use less memory and we use it ...
Definition RectangleFlashAnimatorComponent.h:17
Definition Rectangle_w_Color.h:6
Definition Window.h:12
Definition AnimatorManager.h:10
Definition FlashAnimation.h:10
Definition Vertex.h:44