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.indexX, flash_animation.indexY,
69 flash_animation.total_frames, flash_animation.speed,
70 flash_animation.type,
71 flash_animation.getSpeedsAsVector(),
72 flash_animation.flashColor,
73 reps ? reps : flash_animation.reps
74 );
75 }
76
77 void resetAnimation() {
78 AnimatorManager& animManager = AnimatorManager::getInstance();
79 animationName = "Default";
80 rectangle->SetFlashAnimation(
81 animManager.flash_animations[animationName].indexX, animManager.flash_animations[animationName].indexY,
82 animManager.flash_animations[animationName].total_frames, animManager.flash_animations[animationName].speed,
83 animManager.flash_animations[animationName].type,
84 animManager.flash_animations[animationName].getSpeedsAsVector(),
85 animManager.flash_animations[animationName].flashColor);
86 }
87
88 std::string getPlayName()
89 {
90 return animationName;
91 }
92
93};
Definition GECS.h:123
T & addComponent(TArgs &&... mArgs)
have addScript function
Definition GECS.h:239
Definition PlaneModelRenderer.h:21
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:18
Definition AnimatorManager.h:10
Definition FlashAnimation.h:10