Sprite.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  3. Permission is hereby granted, free of charge, to any person
  4. obtaining a copy of this software and associated documentation
  5. files (the "Software"), to deal in the Software without
  6. restriction, including without limitation the rights to use,
  7. copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following
  10. conditions:
  11. The above copyright notice and this permission notice shall be
  12. included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  15. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  17. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #pragma once
  23. #include "Types.h"
  24. #include "Frame.h"
  25. #include "List.h"
  26. #include "Data.h"
  27. namespace Crown
  28. {
  29. class VertexBuffer;
  30. class IndexBuffer;
  31. class Sprite
  32. {
  33. public:
  34. Sprite();
  35. ~Sprite();
  36. void draw(int frameNumber);
  37. void draw(int frameNumber, real angle, real scaleX, real scaleY);
  38. void drawFit(int frameNumber, int x, int y, int w, int h);
  39. inline void AddFrame(Frame* frame)
  40. {
  41. mFrames.Append(frame);
  42. }
  43. void RemoveFrame(int frameNumber);
  44. void Clear();
  45. inline Frame* GetFrame(int frameNumber)
  46. {
  47. return mFrames[frameNumber];
  48. }
  49. inline int GetFrameCount()
  50. { return mFrames.GetSize(); }
  51. void SetInterpolation(bool interpolate);
  52. //! Load a sprite from image
  53. static Sprite* LoadSpriteFromImage(const char* filePath);
  54. //! Load a tiled sprite from an image containing the sprite sheet. imgX and imgY are in image coordinates (not cartesian)
  55. static Sprite* LoadSpriteFromImage(const char* filePath, uint tileCount, uint tileRows, uint tileColumns, uint imgX, uint imgY, uint tileSizeX, uint tileSizeY, uint tilePadX, uint tilePadY);
  56. //! Load a tiled sprite from an image containing the sprite sheet plus greyscale alpha.
  57. static Sprite* LoadSpriteFromImage(const char* filePath, const char* alphaFilePath, uint tileCount, uint tileRows, uint tileColumns, uint imgX, uint imgY, uint tileSizeX, uint tileSizeY, uint tilePadX, uint tilePadY);
  58. private:
  59. List<Frame*> mFrames;
  60. bool mInterpolate;
  61. VertexData mVertices[4];
  62. FaceData mFaces[2];
  63. VertexBuffer* mVertexBuffer;
  64. IndexBuffer* mIndexBuffer;
  65. };
  66. } //namespace Crown