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 (sprite->flash_animation.hasFinished()) { // playing again animation
44 sprite->flash_animation.finished = false;
45 sprite->flash_animation.times_played = 0;
46 resetAnimation();
47 }
48
49 sprite->flash_animation.advanceFrame(deltaTime);
50 sprite->setFlashFrame();
51 }
52
53 void draw(size_t e_index, PlaneModelRenderer& batch, TazGraphEngine::Window& window) override
54 {
55 //sprite->draw(batch);
56 }
57
58 void Play(std::string animName, int reps = 0)
59 {
60 AnimatorManager& animManager = AnimatorManager::getInstance();
61 animationName = animName;
62 sprite->SetFlashAnimation(
63 animManager.flash_animations[animationName].indexX, animManager.flash_animations[animationName].indexY,
64 animManager.flash_animations[animationName].total_frames, animManager.flash_animations[animationName].speed,
65 animManager.flash_animations[animationName].type,
66 animManager.flash_animations[animationName].getSpeedsAsVector(),
67 animManager.flash_animations[animationName].flashColor,
68 reps ? reps : animManager.flash_animations[animationName].reps
69 );
70 }
71
72 void resetAnimation() {
73 AnimatorManager& animManager = AnimatorManager::getInstance();
74 animationName = "Default";
75 sprite->SetFlashAnimation(
76 animManager.flash_animations[animationName].indexX, animManager.flash_animations[animationName].indexY,
77 animManager.flash_animations[animationName].total_frames, animManager.flash_animations[animationName].speed,
78 animManager.flash_animations[animationName].type,
79 animManager.flash_animations[animationName].getSpeedsAsVector(),
80 animManager.flash_animations[animationName].flashColor);
81 }
82
83 std::string getPlayName()
84 {
85 return animationName;
86 }
87
88 void DestroyTex()
89 {
90 sprite->DestroyTex();
91 }
92
93};
Definition AnimatorComponent.h:13
T & addComponent(TArgs &&... mArgs)
have addScript function
Definition GECS.h:239
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:21
Definition SpriteComponent.h:17
Definition Window.h:18
Definition AnimatorManager.h:10