/// <summary> /// 开始动画 /// </summary> public void StartAnimalion() { AnimationState = AnimationStates.AnimationStart; if (OnAnimationStartEvent != null) { OnAnimationStartEvent(); } //准备动画 if (iAnimalionInterface != null) { iAnimalionInterface.PrepareAnimalion(); } Thread animalThread = new Thread(() => { if (iInterpolation != null) { AnimationFrameInterpolation = iInterpolation.GetInterpolationValue(); } DateTime startAnimationTime; int sleepTime; AnimationState = AnimationStates.AnimationRuning; while (AnimationState != AnimationStates.AnimationStop) { startAnimationTime = DateTime.Now; //动画绘制 if (iAnimalionInterface != null) { iAnimalionInterface.AnimalionRender(AnimationIndex, AnimationFrameInterpolation, AnimationInterpolation); } AnimationIndex++; if (iInterpolation != null) { AnimationFrameInterpolation = iInterpolation.GetInterpolationValue(); AnimationInterpolation.V1 += AnimationFrameInterpolation.V1; AnimationInterpolation.V2 += AnimationFrameInterpolation.V2; AnimationInterpolation.Tag = AnimationFrameInterpolation.Tag; } AnimalionUsedTimeMilliseconds = AnimationIndex * DelayTime; //如果超过设定的动画时间, 结束动画(如果动画时间为负数,不停止动画) if (AnimalionTime > 0 && AnimalionUsedTimeMilliseconds >= AnimalionTime) { StopAnimation(); } //每帧动画结束 if (iAnimalionInterface != null) { iAnimalionInterface.FrameAnimationFinished(); } if (OnFrameAnimationEndEvent != null) { OnFrameAnimationEndEvent(); } //暂停动画 if (AnimationState == AnimationStates.AnimationPause) { if (OnAnimationPauseWvent != null) { OnAnimationPauseWvent(); } while (AnimationState == AnimationStates.AnimationPause) { Thread.Sleep(200); } } sleepTime = (int)(DelayTime - (DateTime.Now - startAnimationTime).TotalMilliseconds); try { if (sleepTime > 0) { Thread.Sleep(sleepTime); } } catch (Exception) { } } if (OnAnimationFinishedEvent != null) { OnAnimationFinishedEvent(); } }); animalThread.IsBackground = true; animalThread.Priority = ThreadPriority.Highest; animalThread.Start(); }