2012-07-04 4 views
0

행동 안에 애니메이션이 있지만 액체가 나오지 않습니다. 내가스토리 보드로 유체 애니메이션을 얻는 방법

int keyFrameCount = 360; 

for (int i = 0; i < keyFrameCount; i++) 
{ 
    animation.KeyFrames.Add(new LinearDoubleKeyFrame(i, keyTime.FromTimeSpan(TimeSpan.FromSeconds(i * timeOffsetInSeconds)))); 
} 

그것은 매우 부드러운 원을 회전합니다을 선택하면,

DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames(); 

animation.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(0).(1)", UIElement.RenderTransformProperty, RotateTransform.AngleProperty)); 

int keyFrameCount = 16; 
double timeOffsetInSeconds = 0.1; 
int targetValue = 12; 

double totalAnimationLength = keyFrameCount * timeOffsetInSeconds; 
double repeatInterval = RepeatInterval; 
bool isShaking = IsShaking; 

// Can't be less than zero and pointless to be less than total length 
if (repeatInterval < totalAnimationLength) 
    repeatInterval = totalAnimationLength; 

animation.Duration = new Duration(TimeSpan.FromSeconds(repeatInterval)); 

for (int i = 0; i < keyFrameCount; i++) 
{ 
    animation.KeyFrames.Add(new LinearDoubleKeyFrame(i % 2 == 0 ? targetValue : -targetValue, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(i * timeOffsetInSeconds)))); 
} 

animation.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(totalAnimationLength)))); 

그러나 :

여기 내 애니메이션 코드입니다.

애니메이션을 0에서 30도, 다시 -30도, 으로 이동시킨 다음 다시 0으로 돌려 놓으면 (비트 주위에서 디더링) 애니메이션을 유창하게 보일 수 있습니다.

일부 시도 후, 나는 (정상적인) 앞뒤로 작동하지 않습니다, 그것은 완전히 제어 할 수없는 행동을 참조하십시오!

답변

2

난 당신이 너무 많은 키 프레임 자신을하고있는 이유를 정말 잘 모르겠지만, 위해 할

나는 애니메이션이 -30 다시, 0 ~ 30도에서 놓아 달성 할 수있는 방법

도, 다시 0으로 돌아가서 (조금 주위를 디더링하도록) 유창하게 보입니다.

당신은

DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames(); 

animation.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(0).(1)", UIElement.RenderTransformProperty, RotateTransform.AngleProperty)); 

var totalAnimationLength = 1600; // Milliseconds 

double repeatInterval = 1600;// Milliseconds 

if (repeatInterval < totalAnimationLength) repeatInterval = totalAnimationLength; // Can't be less than zero and pointless to be less than total length 

animation.Duration = new Duration(TimeSpan.FromMilliseconds(repeatInterval)); 
animation.RepeatBehavior = RepeatBehavior.Forever; // assuming this was intended from having a repeat interval? 

animation.KeyFrames.Add(new LinearDoubleKeyFrame(30, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(totalAnimationLength * 0.25)))); 
animation.KeyFrames.Add(new LinearDoubleKeyFrame(-30, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(totalAnimationLength * 0.75)))); 
animation.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(totalAnimationLength)))); 
+0

작품 완벽처럼 뭔가 애니메이션을 변경할 수 있습니다! 고마워요! –

관련 문제