Silverlight动画与多媒体应用详解
1. Silverlight动画基础与实现
在Silverlight中进行动画开发时,若椭圆尚未到达画布底部,代码会增加其速度。也可以根据椭圆与画布底部的接近程度来设置速度,以实现类似磁铁的效果。以下是相关代码逻辑:
if (top >= (canvas.ActualHeight - ellipseRadius*2)) { // This circle has reached the bottom. // Stop animating it. ellipses.Remove(info); } else { // Increase the velocity. info.VelocityY += accelerationY; }当所有椭圆都从集合中移除时,事件处理程序会被移除,动画结束:
if (ellipses.Count == 0) { // End the animation. // There's no reason to keep calling this method // if it has no work to do. CompositionTarget.Rendering -= RenderFrame; rendering = false; }显然,可以扩展这个动画,让圆实现弹跳、分散等效果,只是需要使用更复杂的公式来计算速度。