SpriteBase.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_BASE_H_
  23. #include "2d/core/SpriteBase.h"
  24. #endif
  25. #ifndef _DGL_H_
  26. #include "graphics/dgl.h"
  27. #endif
  28. // Script bindings.
  29. #include "2d/core/SpriteBase_ScriptBinding.h"
  30. //------------------------------------------------------------------------------
  31. IMPLEMENT_CONOBJECT(SpriteBase);
  32. //------------------------------------------------------------------------------
  33. SpriteBase::SpriteBase()
  34. {
  35. }
  36. //------------------------------------------------------------------------------
  37. SpriteBase::~SpriteBase()
  38. {
  39. }
  40. //------------------------------------------------------------------------------
  41. void SpriteBase::initPersistFields()
  42. {
  43. // Call parent.
  44. Parent::initPersistFields();
  45. addProtectedField("Image", TypeImageAssetPtr, Offset(mImageAsset, SpriteBase), &setImage, &getImage, &writeImage, "");
  46. addProtectedField("Frame", TypeS32, Offset(mImageFrame, SpriteBase), &setImageFrame, &defaultProtectedGetFn, &writeImageFrame, "");
  47. addProtectedField("NamedFrame", TypeString, Offset(mNamedImageFrame, SpriteBase), &setNamedImageFrame, &defaultProtectedGetFn, &writeNamedImageFrame, "");
  48. addProtectedField("Animation", TypeAnimationAssetPtr, Offset(mAnimationAsset, SpriteBase), &setAnimation, &getAnimation, &writeAnimation, "");
  49. }
  50. //-----------------------------------------------------------------------------
  51. void SpriteBase::integrateObject( const F32 totalTime, const F32 elapsedTime, DebugStats* pDebugStats )
  52. {
  53. // Call Parent.
  54. Parent::integrateObject( totalTime, elapsedTime, pDebugStats );
  55. // Update image frame provider.
  56. ImageFrameProvider::update( elapsedTime );
  57. }
  58. //------------------------------------------------------------------------------
  59. bool SpriteBase::validRender( void ) const
  60. {
  61. return ImageFrameProvider::validRender();
  62. }
  63. //------------------------------------------------------------------------------
  64. void SpriteBase::copyTo(SimObject* object)
  65. {
  66. // Call to parent.
  67. Parent::copyTo(object);
  68. // Cast to sprite.
  69. SpriteBase* pSpriteBase = static_cast<SpriteBase*>(object);
  70. // Sanity!
  71. AssertFatal(pSpriteBase != NULL, "SpriteBase::copyTo() - Object is not the correct type.");
  72. // Call image frame provider.
  73. ImageFrameProvider::copyTo( pSpriteBase );
  74. }
  75. //------------------------------------------------------------------------------
  76. void SpriteBase::onAnimationEnd( void )
  77. {
  78. // Do script callback.
  79. Con::executef( this, 1, "onAnimationEnd" );
  80. }