共用方式為


KeyFrameAnimation.Direction 屬性

定義

動畫現正播放的方向。

Direction屬性可讓您在動畫有大於一個的IterationCount時,從頭到端或端對端驅動動畫,從開始或端對端開始或替代。 這可讓您輕鬆自訂動畫定義。

public:
 property AnimationDirection Direction { AnimationDirection get(); void set(AnimationDirection value); };
AnimationDirection Direction();

void Direction(AnimationDirection value);
public AnimationDirection Direction { get; set; }
var animationDirection = keyFrameAnimation.direction;
keyFrameAnimation.direction = animationDirection;
Public Property Direction As AnimationDirection

屬性值

動畫現正播放的方向。

範例

AnimationDirection 為 Normal

class Direction 
{ 
  Direction(Compositor compositor, SpriteVisual heroVisual) 
  { 
    Vector3KeyFrameAnimation animation = compositor.CreateVector3KeyFrameAnimation(); 
    animation.InsertKeyFrame(0f, new Vector3(0f,0f,0f)); 
    animation.InsertKeyFrame(1f, new Vector3(20f,20f,0f)); 
    animation.Duration = TimeSpan.FromSeconds(0.25); 

    // Run animation for 4 times 
    animation.IterationCount = 4; 

    // Direction of animation is normal i.e. forward. 
    animation.Direction = AnimationDirection.Normal; 

    heroVisual.StartAnimation("Offset", animation); 
  } 
} 

AnimationDirection 為 Reverse

class Direction 
{ 
  Direction(Compositor compositor, SpriteVisual heroVisual) 
  { 
    Vector3KeyFrameAnimation animation = compositor.CreateVector3KeyFrameAnimation(); 
    animation.InsertKeyFrame(0f, new Vector3(0f,0f,0f)); 
    animation.InsertKeyFrame(1f, new Vector3(20f,20f,0f)); 
    animation.Duration = TimeSpan.FromSeconds(0.25); 

    // Run animation for 4 times 
    animation.IterationCount = 4; 

    // Direction of animation is Reverse i.e. end to start. 
    animation.Direction = AnimationDirection.Reverse; 

    heroVisual.StartAnimation("Offset", animation); 
  } 
} 

AnimationDirection 是替代的

class Direction 
{ 
  Direction(Compositor compositor, SpriteVisual heroVisual) 
  { 
    Vector3KeyFrameAnimation animation = compositor.CreateVector3KeyFrameAnimation(); 
    animation.InsertKeyFrame(0f, new Vector3(0f,0f,0f)); 
    animation.InsertKeyFrame(1f, new Vector3(20f,20f,0f)); 
    animation.Duration = TimeSpan.FromSeconds(0.25); 

    // Run animation for 4 times 
    animation.IterationCount = 4; 

    // Direction of animation is alternate i.e. start to end and then end to start and so on. 
    animation.Direction = AnimationDirection.Alternate; 

    heroVisual.StartAnimation("Offset", animation); 
  } 
} 

AnimationDirection 是 AlternateReverse

class Direction 
{ 
  Direction(Compositor compositor, SpriteVisual heroVisual) 
  { 
    Vector3KeyFrameAnimation animation = compositor.CreateVector3KeyFrameAnimation(); 
    animation.InsertKeyFrame(0f, new Vector3(0f,0f,0f)); 
    animation.InsertKeyFrame(1f, new Vector3(20f,20f,0f)); 
    animation.Duration = TimeSpan.FromSeconds(0.25); 

    // Run animation for 4 times 
    animation.IterationCount = 4; 

    // Direction of animation is alternate-reverse i.e. end to start and then start to end and so on. 
    animation.Direction = AnimationDirection.AlternateReverse; 

    heroVisual.StartAnimation("Offset", animation); 
  } 
} 

備註

假設有反覆運算計數為 3 和兩個主要畫面格的位移動畫 (0,而 1 個) 值為 Vector3 (5,5,5) ,而 Keyframe 0 的值則為 Vector3, (20,20,20,20) ,20,20,20,20,1,下表顯示具有不同方向值的動畫行為。

方向動畫行為
正常動畫會從位移值 Vector3 (5,5,5) 開始,並移至 Vector3 (20,20,20) ,重複 3 次一律從 (5,5,5) 開始。
Reverse動畫會以反向開始和位移值 (20,20,20) ,並移至 (5,5,5) 重複 3 次,一律從 (20,20,20,20) 開始。
替代在第一次反覆運算中,動畫會從位移值 (5,5,5) 開始,並移至 (20,20,20) 。 第二個反復專案動畫會從位移值 (20,20,20) 開始,然後移至 (5,5,5) 。 在第三次和最後的反復專案中,動畫會從位移 (5,5,5) 開始,並移至 (20,20,20) 。
AlternateReverse在第一次反覆運算中,動畫會從位移值 (20,20,20) 開始,並移至 (5,5,5) 。 第二次反覆運算中,動畫會從位移值 (5,5,5) 開始,並移至 (20, 20, 20) 。 在第三次和最後的反復專案中,動畫會從位移 (20、20、20) 開始,並移至 (5,5,5) 。

適用於