dl
dl_animation.h
浏览该文件的文档.
1
12#pragma once
13
14#include "dl_type.h"
15#include "render/dl_sprite.h"
16
17namespace dl
18{
19
21{
22 NORMAL, // 播放
23 PAUSE, // 暂停
24 STOP, // 停止
25};
32
34{
35public:
37 void Replay(unsigned tkc);
39 void Play(unsigned tkc);
41 void Pause(unsigned tkc);
43 void Stop();
45 bool IsPlayEnd()
46 {
47 return _countMax && _count >= _countMax;
48 }
49
50 void SetPlayCountMax(unsigned count_max) { _countMax = count_max; }
51
52 unsigned GetPlayCount() { return _count; }
53 unsigned GetPlayCountMax() { return _countMax; }
54 size_t GetFrameCount() { return _vecFtime.size(); }
55 std::string GetName() { return _name; }
56 unsigned GetDir() { return _dir; }
57
58
59 void Render(unsigned tkc);
60
61 void PushBack(gcSprite spr, unsigned ftime = 0);
62 void SetFrameTime(unsigned ftime);
63
65 {
66 _coor = Coor::Create();
67 for (auto& spr : _vecSpr)
68 {
69 spr->SetCoor(_coor);
70 }
71 }
72
73 Coor* GetCoor() { return _coor; }
74
75 std::string Dump(unsigned tkc);
76
77 Animation(std::string_view name, unsigned dir) :
78 _name{ name },
79 _dir{ dir },
80 _countMax{ 1 },
81 _speed{ 1.0f },
82 _tkcPlayed{ 0 },
83 _tkcBegin{ 0 },
84 _cur{ 0 },
85 _count{ 0 },
86 _state{ AnimationState::NORMAL },
87 _end{ AnimationEnd::STOP },
88 _coor{ nullptr }
89 { }
91 {
92 delete _coor;
93 }
94private:
95 std::string _name;
96 unsigned _dir;
97 std::vector<gcSprite> _vecSpr;
98 std::vector<unsigned> _vecFtime; // 每一帧的间隔
99 unsigned _countMax; // 最大播放次数,0为无限
100 float _speed; // 播放速度
101 unsigned _tkcPlayed;// 当前帧已经播放的时间(仅pause记录,用于恢复)
102
103 unsigned _tkcBegin; // 当前帧播放起始时间
104 unsigned _cur; // 当前帧
105 unsigned _count; // 当前播放次数
106 AnimationState _state;
107 AnimationEnd _end;
108
109 Coor* _coor;
110 unsigned _get_played(unsigned tkc);
111};
112
114}
std::string GetName()
unsigned GetPlayCountMax()
Animation(std::string_view name, unsigned dir)
void SetFrameTime(unsigned ftime)
void SetPlayCountMax(unsigned count_max)
unsigned GetPlayCount()
void Pause(unsigned tkc)
暂停播放
void Render(unsigned tkc)
void Replay(unsigned tkc)
从头开始播放
void Stop()
停止播放,并回到开始
void PushBack(gcSprite spr, unsigned ftime=0)
bool IsPlayEnd()
是否播放完成
std::string Dump(unsigned tkc)
void Play(unsigned tkc)
从当前位置开始播放
2d坐标系
static Coor * Create(Coor *parent=nullptr)
引用计数对象,通过get_gc函数创建
2d绘图元素
通用类型
@ DISAPPEAR
播完后不显示
GC< Sprite > gcSprite
GC< Animation > gcAnimation