Animation2D.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // Copyright (c) 2008-2014 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. #include "Precompiled.h"
  23. #include "Animation2D.h"
  24. #include "AnimationSet2D.h"
  25. #include "Sprite2D.h"
  26. #include "DebugNew.h"
  27. namespace Urho3D
  28. {
  29. ObjectRef::ObjectRef() :
  30. isBone_(false),
  31. parent_(-1),
  32. timeline_(0),
  33. key_(0),
  34. zIndex_(0)
  35. {
  36. }
  37. MainlineKey::MainlineKey() :
  38. time_(0)
  39. {
  40. }
  41. const ObjectRef* MainlineKey::GetObjectRef(int timeline) const
  42. {
  43. for (unsigned i = 0; i < objectRefs_.Size(); ++i)
  44. {
  45. if (timeline == objectRefs_[i].timeline_)
  46. return &objectRefs_[i];
  47. }
  48. return 0;
  49. }
  50. ObjectKey::ObjectKey() :
  51. time_(0.0f),
  52. spin_(1),
  53. angle_(0.0f),
  54. scale_(Vector2::ONE),
  55. hotSpot_(0.0f, 1.0f),
  56. alpha_(1.0f)
  57. {
  58. }
  59. Timeline::Timeline() :
  60. isBone_(false)
  61. {
  62. }
  63. Animation2D::Animation2D(AnimationSet2D* animationSet) :
  64. animationSet_(animationSet),
  65. length_(0.0f),
  66. looped_(true)
  67. {
  68. }
  69. Animation2D::~Animation2D()
  70. {
  71. }
  72. void Animation2D::SetName(const String& name)
  73. {
  74. name_ = name;
  75. }
  76. void Animation2D::SetLength(float length)
  77. {
  78. length_ = Max(0.0f, length);
  79. }
  80. void Animation2D::SetLooped(bool looped)
  81. {
  82. looped_ = looped;
  83. }
  84. void Animation2D::AddMainlineKey(const MainlineKey& mainlineKey)
  85. {
  86. mainlineKeys_.Push(mainlineKey);
  87. }
  88. void Animation2D::AddTimeline(const Timeline& timeline)
  89. {
  90. timelines_.Push(timeline);
  91. }
  92. AnimationSet2D* Animation2D::GetAnimationSet() const
  93. {
  94. return animationSet_;
  95. }
  96. }