Oxygine  1
2g game engine
ResAnim.h
1 #pragma once
2 #include "oxygine-include.h"
3 #include "Resource.h"
4 #include "AnimationFrame.h"
5 #include "core/Texture.h"
6 #include <vector>
7 
8 namespace oxygine
9 {
10  typedef std::vector<AnimationFrame> animationFrames;
11 
12  DECLARE_SMART(ResAnim, spResAnim);
13  class ResAnim: public Resource
14  {
15  INHERITED(Resource);
16  public:
17  ResAnim(Resource* atlas = 0);
18  ~ResAnim();
19 
20  void init(const std::string& file, int columns = 1, int rows = 1, float scaleFactor = 1.0f);
21  virtual void init(Image* original, int columns = 1, int rows = 1, float scaleFactor = 1.0f);
22  void init(animationFrames& frames, int columns, float scaleFactor = 1.0f, float appliedScale = 1.0f);
24  void init(spNativeTexture texture, const Point& originalSize, int columns = 1, int rows = 1, float scaleFactor = 1.0f);
25 
26  /*adds additional column. use it only if rows = 1*/
27  //void addFrame(const AnimationFrame &frame);
28 
29  float getScaleFactor() const {return _scaleFactor;}
30  float getAppliedScale() const { return _appliedScale; }
31  int getColumns() const {return _columns;}
32  int getRows() const {return (int)_frames.size() / _columns;}
33  int getTotalFrames() const {return (int)_frames.size();}
34  int getFrameRate() const { return _framerate; }
35  const Resources* getResources() const;
36  const AnimationFrame& getFrame(int col, int row) const;
38  const AnimationFrame& getFrame(int index) const;
40  Resource* getAtlas() {return _atlas;}
42  const Vector2& getSize() const;
43  float getWidth() const;
44  float getHeight() const;
45 
46  void setFrame(int col, int row, const AnimationFrame& frame);
47  void setFrameRate(int v) { _framerate = v; }
48  void removeFrames();
49 
50  operator const AnimationFrame& ();
51 
52  protected:
53 
54  void _load(LoadResourcesContext* ctx = 0) override;
55  void _unload() override;
56 
57  int _columns;
58  Resource* _atlas;
59  float _scaleFactor;
60  float _appliedScale;
61  int _framerate;
62 
63  animationFrames _frames;
64  };
65 }
Definition: Image.h:23
Definition: AnimationFrame.h:28
–oxgl-end–!
Definition: Actor.h:14
Definition: Resource.h:10
Definition: ResAnim.h:13
Resource * getAtlas()
Definition: ResAnim.h:40
Definition: Resources.h:43
const Vector2 & getSize() const