SpriterInstance2D.h 3.4 KB

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