Sprite.cc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SPRITE_H_
  23. #include "Sprite.h"
  24. #endif
  25. #ifndef _DGL_H_
  26. #include "graphics/dgl.h"
  27. #endif
  28. #ifndef _STRINGBUFFER_H_
  29. #include "string/stringBuffer.h"
  30. #endif
  31. // Script bindings.
  32. #include "Sprite_ScriptBinding.h"
  33. //------------------------------------------------------------------------------
  34. IMPLEMENT_CONOBJECT(Sprite);
  35. //------------------------------------------------------------------------------
  36. Sprite::Sprite() :
  37. mFlipX(false),
  38. mFlipY(false)
  39. {
  40. }
  41. //------------------------------------------------------------------------------
  42. Sprite::~Sprite()
  43. {
  44. }
  45. //------------------------------------------------------------------------------
  46. void Sprite::copyTo(SimObject* object)
  47. {
  48. // Call to parent.
  49. Parent::copyTo(object);
  50. // Cast to sprite.
  51. Sprite* pSprite = static_cast<Sprite*>(object);
  52. // Sanity!
  53. AssertFatal(pSprite != NULL, "Sprite::copyTo() - Object is not the correct type.");
  54. /// Render flipping.
  55. pSprite->setFlip( getFlipX(), getFlipY() );
  56. }
  57. //------------------------------------------------------------------------------
  58. void Sprite::initPersistFields()
  59. {
  60. // Call parent.
  61. Parent::initPersistFields();
  62. /// Render flipping.
  63. addField("FlipX", TypeBool, Offset(mFlipX, Sprite), &writeFlipX, "");
  64. addField("FlipY", TypeBool, Offset(mFlipY, Sprite), &writeFlipY, "");
  65. }
  66. //------------------------------------------------------------------------------
  67. void Sprite::sceneRender( const SceneRenderState* pSceneRenderState, const SceneRenderRequest* pSceneRenderRequest, BatchRender* pBatchRenderer )
  68. {
  69. // Let the parent render.
  70. ImageFrameProvider::render(
  71. getFlipX(), getFlipY(),
  72. mRenderOOBB[0],
  73. mRenderOOBB[1],
  74. mRenderOOBB[2],
  75. mRenderOOBB[3],
  76. pBatchRenderer );
  77. }