SpriterInstance2D.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  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 deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // 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 FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Atomic2D/SpriterData2D.h"
  24. namespace Atomic
  25. {
  26. class Component;
  27. namespace Spriter
  28. {
  29. /// Loop Mode.
  30. enum LoopMode
  31. {
  32. Default = 0,
  33. ForceLooped,
  34. ForceClamped,
  35. };
  36. /// Spriter instance.
  37. class SpriterInstance
  38. {
  39. public:
  40. /// Constructor with spriter data.
  41. SpriterInstance(Component* owner, SpriterData* spriteData);
  42. /// Destructor.
  43. ~SpriterInstance();
  44. /// Set current entity.
  45. bool SetEntity(int index);
  46. /// Set current entity.
  47. bool SetEntity(const String& entityName);
  48. /// Set current animation.
  49. bool SetAnimation(int index, LoopMode loopMode = Default);
  50. /// Set current animation.
  51. bool SetAnimation(const String& animationName, LoopMode loopMode = Default);
  52. /// Set root spatial info.
  53. void setSpatialInfo(const SpatialInfo& spatialInfo);
  54. /// Set root spatial info.
  55. void setSpatialInfo(float x, float y, float angle, float scaleX, float scaleY);
  56. /// Update animation.
  57. void Update(float delta_time);
  58. /// Return current entity.
  59. Entity* GetEntity() const { return entity_; }
  60. /// Return current animation.
  61. Animation* GetAnimation() const { return animation_; }
  62. /// Return root spatial info.
  63. const SpatialInfo& GetSpatialInfo() const { return spatialInfo_; }
  64. /// Return animation result timeline keys.
  65. const PODVector<SpatialTimelineKey*>& GetTimelineKeys() const { return timelineKeys_; }
  66. private:
  67. /// Handle set entity.
  68. void OnSetEntity(Entity* entity);
  69. /// Handle set animation.
  70. void OnSetAnimation(Animation* animation, LoopMode loopMode = Default);
  71. /// Update mainline key.
  72. void UpdateMainlineKey();
  73. /// Update timeline keys.
  74. void UpdateTimelineKeys();
  75. /// Get timeline key by ref.
  76. TimelineKey* GetTimelineKey(Ref* ref) const;
  77. /// Clear mainline key and timeline keys.
  78. void Clear();
  79. /// Parent component.
  80. Component* owner_;
  81. /// Spriter data.
  82. SpriterData* spriterData_;
  83. /// Current entity.
  84. Entity* entity_;
  85. /// Current animation.
  86. Animation* animation_;
  87. /// Looping.
  88. bool looping_;
  89. /// Root spatial info.
  90. SpatialInfo spatialInfo_;
  91. /// Current time.
  92. float currentTime_;
  93. /// Current mainline key.
  94. MainlineKey* mainlineKey_;
  95. /// Current timeline keys.
  96. PODVector<SpatialTimelineKey*> timelineKeys_;
  97. };
  98. }
  99. }