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