Procházet zdrojové kódy

Add hot spot in Sprite.

aster2013 před 11 roky
rodič
revize
a5a0512cf8

+ 1 - 1
Source/Engine/Urho2D/XAnimatedSprite2D.cpp

@@ -311,7 +311,7 @@ void XAnimatedSprite2D::UpdateAnimation(float timeStep)
                     objectNode->SetScale(currKey.scale_.Lerp(nextKey.scale_, t));
 
                     staticSprite->SetSprite(currKey.sprite_);
-                    staticSprite->SetHotSpot(currKey.pivot_.Lerp(nextKey.pivot_, t));
+                    staticSprite->SetHotSpot(currKey.hotSpot_.Lerp(nextKey.hotSpot_, t));
                     float alpha_ = Lerp(currKey.alpha_, nextKey.alpha_, t);
                     staticSprite->SetColor(Color(1.0f, 1.0f, 1.0f, alpha_));
 

+ 1 - 1
Source/Engine/Urho2D/XAnimation2D.cpp

@@ -54,7 +54,7 @@ const ObjectRef* MainlineKey::GetObjectRef(int timeline) const
 
 ObjectKey::ObjectKey() :
     time_(0.0f),
-    pivot_(0.0f, 1.0f),
+    hotSpot_(0.0f, 1.0f),
     scale_(Vector2::ONE), 
     spin_(1),
     alpha_(1.0f)

+ 2 - 2
Source/Engine/Urho2D/XAnimation2D.h

@@ -74,8 +74,8 @@ struct ObjectKey
     SharedPtr<Sprite2D> sprite_;
     /// Position.
     Vector2 position_;
-    /// Pivot (hot spot).
-    Vector2 pivot_;
+    /// Hot spot (pivot).
+    Vector2 hotSpot_;
     /// Scale.
     Vector2 scale_;
     /// Spin direction.

+ 13 - 2
Source/Engine/Urho2D/XAnimationSet2D.cpp

@@ -136,6 +136,13 @@ bool XAnimationSet2D::LoadFolders(const XMLElement& rootElem)
                 LOGERROR("Could not load sprite " + parentPath + fileName);
                 return false;
             }
+            
+            Vector2 hotSpot(0.0f, 1.0f);
+            if (fileElem.HasAttribute("pivot_x"))
+                hotSpot.x_ = fileElem.GetFloat("pivot_x");
+            if (fileElem.HasAttribute("pivot_y"))
+                hotSpot.y_ = fileElem.GetFloat("pivot_y");
+            sprite->SetHotSpot(hotSpot);
 
             sprites_[(folderId << 16) + fileId] = sprite;
         }
@@ -210,10 +217,14 @@ bool XAnimationSet2D::LoadAnimation(const XMLElement& animationElem)
             objectKey.position_.y_ = objectElem.GetFloat("y") * PIXEL_SIZE;
             
             if (objectElem.HasAttribute("pivot_x"))
-                objectKey.pivot_.x_ = objectElem.GetFloat("pivot_x");
+                objectKey.hotSpot_.x_ = objectElem.GetFloat("pivot_x");
+            else
+                objectKey.hotSpot_.x_ = objectKey.sprite_->GetHotSpot().x_;
 
             if (objectElem.HasAttribute("pivot_y"))
-                objectKey.pivot_.y_ = objectElem.GetFloat("pivot_y");
+                objectKey.hotSpot_.y_ = objectElem.GetFloat("pivot_y");
+            else
+                objectKey.hotSpot_.y_ = objectKey.sprite_->GetHotSpot().y_;
 
             if (objectElem.HasAttribute("scale_x"))
                 objectKey.scale_.x_ = objectElem.GetFloat("scale_x");