SDXFrameWork  0.09
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Anime.h
1 #pragma once//©SDXFramework http://sourceforge.jp/projects/dxframework/
2 #include <Multimedia/SDX.h>
3 #include <Multimedia/Image.h>
4 #include <Framework/ImagePack.h>
5 
6 namespace SDX
7 {
10 enum class NextFrame
11 {
12  Normal = -10000,
13  ToFront ,
14  ToBack ,
15  End ,
16 };
17 
19 enum class AnimeType
20 {
21  Normal,
22  Reverse,
23  End
24 };
25 
28 class Anime : public ImagePack
29 {
30 private:
31  std::vector<unsigned int> times;
32  std::vector<int> nexts;
33 public:
35  class Player
36  {
37  private:
38  const Anime* anime;//対応アニメ
39  int direct = 1;//進行方向
40  int frameNumber = 0;//現在のコマ
41  double timer = 0;//経過時間
42  public:
43 
44  Player(const Anime* 親アニメ) :
45  anime(親アニメ)
46  {}
47 
49  bool Update( double 経過フレーム = 1)
50  {
51  timer += 経過フレーム;
52 
53  if( timer > anime->times[frameNumber] )
54  {
55  timer -= anime->times[frameNumber];
56  switch ( anime->nexts[frameNumber] )
57  {
58  case (int)NextFrame::Normal:
59  frameNumber += direct;
60  break;
61  case (int)NextFrame::ToFront:
62  direct = 1;
63  frameNumber += direct;
64  break;
65  case (int)NextFrame::ToBack:
66  direct = -1;
67  frameNumber += direct;
68  break;
69  case (int)NextFrame::End:
70  return false;
71  break;
72  default:
73  frameNumber = anime->nexts[frameNumber];
74  break;
75  }
76 
77  if ((unsigned int)frameNumber >= anime->images.size()) frameNumber = 0;
78  if (frameNumber < 0) frameNumber = (int)anime->images.size() - 1;
79  }
80 
81  return true;
82  }
83 
86  {
87  return anime[0][frameNumber];
88  }
89 
91  void SetFrame(int コマ数 )
92  {
93  this->frameNumber = コマ数;
94  timer = 0;
95  }
96  };
97 
98  Anime(){};
99 
100  Anime(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦, int 再生フレーム数 = 1) :
101  ImagePack( ファイル名 , 総コマ数 ,コマ割り横 , コマ割り縦)
102  {
103  for( unsigned int a=0; a<times.size() ; ++a )
104  {
105  times.push_back(再生フレーム数);
106  nexts.push_back((int)NextFrame::Normal);
107  }
108  }
109 
111  bool Load(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦, int 再生フレーム数 = 1)
112  {
113  ImagePack::Load(ファイル名, 総コマ数, コマ割り横, コマ割り縦);
114 
115  for(int a=0 ; a<総コマ数 ; ++a)
116  {
117  times.push_back(再生フレーム数);
118  nexts.push_back((int)NextFrame::Normal);
119  }
120 
121  return true;
122  }
123 
125  bool Load(const char* ファイル名, const char *拡張子, int 総コマ数, int 再生フレーム数 = 1)
126  {
127  for(int a=0 ; a<総コマ数 ; ++a)
128  {
129  char fileBuf[8];
130  sprintf_s( fileBuf , 8 , "%03d." , a );
131  std::string fileName = ファイル名;
132  fileName += fileBuf;
133  fileName += 拡張子;
134 
135  this->Add(new Image(fileName.c_str()), 再生フレーム数);
136  }
137 
138  return true;
139  }
140 
142  void Add(Image *追加イメージ, int 再生フレーム数 = 1)
143  {
144  ImagePack::Add( 追加イメージ );
145  times.push_back(再生フレーム数);
146  nexts.push_back( (int)NextFrame::Normal);
147  }
148  void Add(const char *ファイル名, int 再生フレーム数 = 1)
149  {
150  Add(new Image(ファイル名), 再生フレーム数);
151  }
152 
154  void Release() override
155  {
157  times.clear();
158  nexts.clear();
159  }
160 
163  void SetFrameTime( int フレーム時間[] )
164  {
165  for(unsigned int a=0 ; a< times.size() ; ++a )
166  {
167  times[a] = フレーム時間[a];
168  }
169  }
170 
172  void SetType( AnimeType 再生方法 )
173  {
174  switch(再生方法)
175  {
176  case AnimeType::Normal:
177  nexts[nexts.size()-1] =(int)NextFrame::Normal;
178  break;
179  case AnimeType::Reverse:
180  nexts[0] =(int)NextFrame::ToFront;
181  nexts[nexts.size()-1] =(int)NextFrame::ToBack;
182  break;
183  case AnimeType::End:
184  nexts[nexts.size()-1] =(int)NextFrame::End;
185  break;
186  }
187  }
188 
190  void SetType( int コマ番号 , int 次フレーム )
191  {
192  nexts[コマ番号] = 次フレーム;
193  }
194  void SetType( int コマ番号 , NextFrame 次フレーム )
195  {
196  nexts[コマ番号] = (int)次フレーム;
197  }
198 
200  int GetAnimeTime() const
201  {
202  int totalTime = 0;
203 
204  for( auto it : times )
205  {
206  totalTime += it;
207  }
208 
209  return totalTime;
210  }
211 
212  Image* operator[](int index) const
213  {
214  return images[index];
215  }
216 };
217 }
次のコマに進む
virtual void Release()
Imageをメモリから開放.
Definition: ImagePack.h:90
void SetType(int コマ番号, int 次フレーム)
指定コマの次フレームを設定する.
Definition: Anime.h:190
bool Load(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦, int 再生フレーム数=1)
画像ファイルを分割してメモリへ読み込む.
Definition: Anime.h:111
int GetAnimeTime() const
全コマの合計フレーム時間を返す.
Definition: Anime.h:200
最後まで再生すると、再生方向を反転
void Release() override
Imageを開放し初期化する.
Definition: Anime.h:154
NextFrame
次コマの移動先.
Definition: Anime.h:10
void SetType(AnimeType 再生方法)
アニメの再生方法を指定する.
Definition: Anime.h:172
画像データを表すクラス.
Definition: Image.h:38
コマの進む向きをマイナスにしてから進む
bool Load(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦)
1つの画像を分割して読み込む.
Definition: ImagePack.h:34
void SetFrameTime(int フレーム時間[])
各コマのフレーム数を設定する.
Definition: Anime.h:163
AnimeType
アニメの再生方法.
Definition: Anime.h:19
void SetFrame(int コマ数)
コマの位置を設定.
Definition: Anime.h:91
void Add(Image *追加イメージ, int 再生フレーム数=1)
末尾にImageを追加する。.
Definition: Anime.h:142
Imageをまとめてコマ送りアニメとして表すクラス.
Definition: Anime.h:28
コマの進む向きをプラスにしてから進む
bool Update(double 経過フレーム=1)
カウンタの更新.
Definition: Anime.h:49
Animeの再生情報を管理するクラス.
Definition: Anime.h:35
複数のImageをまとめるクラス.
Definition: ImagePack.h:9
void Add(Image *追加イメージ)
Imageを末尾に追加.
Definition: ImagePack.h:78
最終フレームで再生を停止
このコマでアニメーションを停止する
bool Load(const char *ファイル名, const char *拡張子, int 総コマ数, int 再生フレーム数=1)
連番ファイルを一括して読み込む.
Definition: Anime.h:125
最後まで再生するとまた最初からループ再生
Image * GetFrame()
現在のコマ番号を取得.
Definition: Anime.h:85