dl
dl_animation.h
浏览该文件的文档.
1
12#pragma once
13
14#include "dl_type.h"
15#include "render/dl_sprite.h"
16#include "base/dl_color.h"
17
18namespace dl
19{
20
22{
23 NORMAL, // 播放
24 PAUSE, // 暂停
25 STOP, // 停止
26};
33
35{
36 friend class Factory;
37public:
39 void Replay(unsigned tkc = 0);
41 void Play(unsigned tkc = 0);
43 void Pause(unsigned tkc = 0);
45 void Stop();
47 bool IsPlayEnd()
48 {
49 return _countMax && _count >= _countMax;
50 }
51
52 void SetPlayCountMax(unsigned count_max) { _countMax = count_max; }
54 {
55 for (auto& spr : _vecSpr)
56 {
57 spr->SetSampler(sampler);
58 }
59 }
61 {
62 for (auto& spr : _vecSpr)
63 {
64 spr->SetBlend(type);
65 }
66 }
67 void SetOrder(float z)
68 {
69 _order = z;
70 for (auto& spr : _vecSpr)
71 {
72 spr->SetOrder(z);
73 }
74 }
75 void SetColor(const Color& color)
76 {
77 _color = color;
78 for (auto& spr : _vecSpr)
79 {
80 spr->SetColor(_color);
81 }
82 }
83 void SetBright(float bright)
84 {
85 _bright = bright;
86 for (auto& spr : _vecSpr)
87 {
88 spr->SetBright(_bright);
89 }
90 }
91
92 unsigned GetPlayCount() { return _count; }
93 unsigned GetPlayCountMax() { return _countMax; }
94 size_t GetFrameCount() { return _vecFtime.size(); }
95 std::string GetName() { return _name; }
96 unsigned GetDir() { return _dir; }
97 unsigned GetFrameTime(size_t i);
98 Color GetColor() { return _color; }
99
100
101 void Render(unsigned tkc = 0);
102
103 void PushBack(gcSprite spr, unsigned ftime = 0);
104 void SetFrameTime(unsigned ftime);
105
107 {
108 _coor = Coor::Create();
109 for (auto& spr : _vecSpr)
110 {
111 spr->SetCoor(_coor);
112 }
113 }
114
115 Coor* GetCoor() { return _coor; }
116 float GetOrder() { return _order; }
117 bool IsPickup()
118 {
119 return _vecSpr[_cur]->IsPickup();
120 }
121
122 std::string Dump(unsigned tkc = 0);
123
124 Animation(std::string_view name, unsigned dir) :
125 _name{ name },
126 _dir{ dir },
127 _countMax{ 1 },
128 _speed{ 1.0f },
129 _tkcPlayed{ 0 },
130 _tkcBegin{ 0 },
131 _cur{ 0 },
132 _count{ 0 },
133 _state{ AnimationState::NORMAL },
134 _end{ AnimationEnd::STOP },
135 _order{ Z_DEFAULT },
136 _bright{ 1.0f },
137 _color{ ColorDef::WHITE },
138 _coor{ nullptr }
139 { }
141 {
142 delete _coor;
143 }
144private:
145 std::string _name;
146 unsigned _dir;
147 std::vector<gcSprite> _vecSpr;
148 std::vector<unsigned> _vecFtime; // 每一帧的间隔
149 unsigned _countMax; // 最大播放次数,0为无限
150 float _speed; // 播放速度
151 unsigned _tkcPlayed;// 当前帧已经播放的时间(仅pause记录,用于恢复)
152
153 unsigned _tkcBegin; // 当前帧播放起始时间
154 unsigned _cur; // 当前帧
155 unsigned _count; // 当前播放次数
156 AnimationState _state;
157 AnimationEnd _end;
158
159 float _order;
160 float _bright;
161 Color _color;
162
163 Coor* _coor;
164 unsigned _get_played(unsigned tkc);
165};
166
168}
std::string GetName()
unsigned GetPlayCountMax()
friend class Factory
void SetSampler(Sprite::Sampler sampler)
Animation(std::string_view name, unsigned dir)
void SetFrameTime(unsigned ftime)
void SetPlayCountMax(unsigned count_max)
void Render(unsigned tkc=0)
unsigned GetPlayCount()
void SetBright(float bright)
void Pause(unsigned tkc=0)
暂停播放
void Play(unsigned tkc=0)
从当前位置开始播放
void Stop()
停止播放,并回到开始
unsigned GetFrameTime(size_t i)
void PushBack(gcSprite spr, unsigned ftime=0)
bool IsPlayEnd()
是否播放完成
void SetOrder(float z)
void Replay(unsigned tkc=0)
从头开始播放
void SetColor(const Color &color)
std::string Dump(unsigned tkc=0)
void SetBlend(Sprite::Blend type)
2d坐标系
static Coor * Create(Coor *parent=nullptr)
引用计数对象,通过get_gc函数创建
2d绘图元素
通用类型
颜色预定义
@ DISAPPEAR
播完后不显示
constexpr float Z_DEFAULT
GC< Sprite > gcSprite
GC< Animation > gcAnimation
Array< float, 4 > Color