TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_sprite.hpp
1 
9 #ifndef TurtleBrains_Sprite_hpp
10 #define TurtleBrains_Sprite_hpp
11 
12 #include <turtle_brains/graphics/tb_graphic.hpp>
13 #include <turtle_brains/graphics/tb_texture_manager.hpp>
14 #include <turtle_brains/graphics/tb_color.hpp>
15 
16 namespace TurtleBrains
17 {
18  namespace Graphics
19  {
20 
29  struct SpriteFrame
30  { //TODO: TIM: Planning: These may turn into PixelSpace values, (int), that is what they are, but they are used as float.
31  float x;
32  float y;
33  float w;
34  float h;
40 
41  //Optimize: TurtleBrains: It might be worth doing this for both optimizing for texture lookups and
42  //convenience/optimization if using a texture packing tool that rotates sprites and cuts transparency away from the sprite.
43  //PixelSpace mTextureWidth;
44  //PixelSpace mTextureHeight; //32bits
45  //rotation byte/ (2bits) //0, 90, 180, 270
46  //32bits offsets, 32bits size change
47 
48 
52  PixelSpace GetPixelTop(void) const;
53 
57  PixelSpace GetPixelLeft(void) const;
58 
62  PixelSpace GetPixelRight(void) const;
63 
67  PixelSpace GetPixelBottom(void) const;
68 
72  PixelSpace GetPixelWidth(void) const;
73 
77  PixelSpace GetPixelHeight(void) const;
78 
82  TexelSpace GetTexelTop(void) const;
83 
87  TexelSpace GetTexelLeft(void) const;
88 
92  TexelSpace GetTexelRight(void) const;
93 
97  TexelSpace GetTexelBottom(void) const;
98 
102  TexelSpace GetTexelWidth(void) const;
103 
107  TexelSpace GetTexelHeight(void) const;
108 
114  static SpriteFrame CreateWith(const TextureHandle& textureHandle);
115 
127  static SpriteFrame CreateWith(const TextureHandle& textureHandle, const PixelSpace& frameX, const PixelSpace& frameY,
128  const PixelSpace& frameWidth, const PixelSpace& frameHeight);
129  };
130 
136  class Sprite : public Graphic
137  {
138  public:
143  explicit Sprite(const SpriteFrame& spriteFrame);
144 
157  explicit Sprite(const tbCore::tbString& textureFile, const PixelSpace& frameX = 0, const PixelSpace& frameY = 0,
158  const PixelSpace& frameWidth = 0, const PixelSpace& frameHeight = 0);
159 
172  explicit Sprite(const TextureHandle& textureHandle, const PixelSpace& frameX = 0, const PixelSpace& frameY = 0,
173  const PixelSpace& frameWidth = 0, const PixelSpace& frameHeight = 0);
174 
185  Sprite(const tbCore::tbString& spriteSheetName, const tbCore::tbString& spriteName);
186 
193  Sprite(const Sprite& other);
194 
198  virtual ~Sprite(void);
199 
206  Sprite& operator=(const Sprite& other);
207 
211  virtual PixelSpace GetPixelWidth(void) const override;
212 
216  virtual PixelSpace GetPixelHeight(void) const override;
217 
225  void SetFlippedHorizontally(bool isFlippedHorizontally);
226 
234  void SetFlippedVertically(bool isFlippedVertically);
235 
239  bool IsFlippedHorizontally(void) const;
240 
244  bool IsFlippedVertically(void) const;
245 
246  protected:
253  virtual void OnRender(void) const override;
254 
262  void SetSpriteFrame(const SpriteFrame& spriteFrame);
263 
267  const SpriteFrame& GetSpriteFrame(void) const;
268 
269  private:
270  SpriteFrame mSpriteFrame;
271  bool mIsFlippedHorizontally;
272  bool mIsFlippedVertically;
273  };
274 
275  }; /* namespace Graphics */
276 }; /* namespace TurtleBrains */
277 
279 
280 #endif /* TurtleBrains_Sprite_hpp */
TexelSpace uvy
Definition: tb_sprite.hpp:36
Definition: tb_graphic.hpp:61
virtual PixelSpace GetPixelHeight(void) const override
TexelSpace uvh
Definition: tb_sprite.hpp:38
float w
Definition: tb_sprite.hpp:33
Sprite(const SpriteFrame &spriteFrame)
virtual void OnRender(void) const override
Give the GameScene and Entities something to display, Text, Sprites and AnimatedSprites help bring th...
PixelSpace GetPixelTop(void) const
Definition: tb_sprite.hpp:29
TexelSpace GetTexelTop(void) const
void SetSpriteFrame(const SpriteFrame &spriteFrame)
TexelSpace GetTexelHeight(void) const
void SetFlippedHorizontally(bool isFlippedHorizontally)
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:21
void SetFlippedVertically(bool isFlippedVertically)
TextureHandle mTexture
Definition: tb_sprite.hpp:39
Sprite & operator=(const Sprite &other)
TexelSpace uvw
Definition: tb_sprite.hpp:37
bool IsFlippedHorizontally(void) const
PixelSpace GetPixelBottom(void) const
PixelSpace GetPixelWidth(void) const
tbCore::uint16 PixelSpace
Definition: tb_texture_manager.hpp:36
virtual PixelSpace GetPixelWidth(void) const override
float y
Definition: tb_sprite.hpp:32
TexelSpace GetTexelRight(void) const
TexelSpace GetTexelWidth(void) const
TexelSpace GetTexelLeft(void) const
PixelSpace GetPixelLeft(void) const
float x
Definition: tb_sprite.hpp:31
TexelSpace GetTexelBottom(void) const
const SpriteFrame & GetSpriteFrame(void) const
float TexelSpace
Definition: tb_texture_manager.hpp:30
std::string tbString
Definition: tb_string.hpp:335
bool IsFlippedVertically(void) const
PixelSpace GetPixelRight(void) const
static SpriteFrame CreateWith(const TextureHandle &textureHandle)
float h
Definition: tb_sprite.hpp:34
TexelSpace uvx
Definition: tb_sprite.hpp:35
PixelSpace GetPixelHeight(void) const
Definition: tb_sprite.hpp:136