TazGraph Project v0.1.0
Loading...
Searching...
No Matches
LineFlashAnimatorComponent.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 LineFlashAnimatorComponent : public LinkComponent //Animator -> Sprite -> Transform
14{
15public:
16
17 Line_w_Color* line = nullptr;
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<Line_w_Color>())
34 {
35 entity->addComponent<Line_w_Color>();
36 }
37 line = &entity->GetComponent<Line_w_Color>();
38
39 Play("Default");
40 }
41
42 void update(float deltaTime) override
43 {
44 if (animationName == "Default") {
45 return;
46 }
47 if (line->flash_animation.hasFinished()) { // playing again animation
48 line->flash_animation.finished = false;
49 line->flash_animation.times_played = 0;
50 resetAnimation();
51 }
52
53 line->flash_animation.advanceFrame(deltaTime);
54 line->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 char* animName, int reps = 0)
63 {
64 AnimatorManager& animManager = AnimatorManager::getInstance();
65 animationName = animName;
66 line->SetFlashAnimation(
67 animManager.flash_animations[animationName].indexX, animManager.flash_animations[animationName].indexY,
68 animManager.flash_animations[animationName].total_frames, animManager.flash_animations[animationName].speed,
69 animManager.flash_animations[animationName].type,
70 animManager.flash_animations[animationName].getSpeedsAsVector(),
71 animManager.flash_animations[animationName].flashColor,
72 reps ? reps : animManager.flash_animations[animationName].reps
73 );
74 }
75
76 void resetAnimation() {
77 AnimatorManager& animManager = AnimatorManager::getInstance();
78 animationName = "Default";
79 line->SetFlashAnimation(
80 animManager.flash_animations[animationName].indexX, animManager.flash_animations[animationName].indexY,
81 animManager.flash_animations[animationName].total_frames, animManager.flash_animations[animationName].speed,
82 animManager.flash_animations[animationName].type,
83 animManager.flash_animations[animationName].getSpeedsAsVector(),
84 animManager.flash_animations[animationName].flashColor);
85 }
86
87 std::string getPlayName()
88 {
89 return animationName;
90 }
91
92};
T & addComponent(TArgs &&... mArgs)
have addScript function
Definition GECS.h:239
Definition LineFlashAnimatorComponent.h:14
Line_w_Color * line
also we use MovingAnimator instead of simple Animator so that entities use less memory and we use it ...
Definition LineFlashAnimatorComponent.h:17
Definition Line_w_Color.h:6
Definition GECS.h:133
Definition PlaneModelRenderer.h:21
Definition Window.h:18
Definition AnimatorManager.h:10