First of all, testing animations is a bit problematic. I made some animations that work terribly in eumulator (although I meet all the requirements like WDDM 1.1), but they work fine on the device. You just need to check it on the device.
, DispatcherTimer ( HelloWorld, ). , .
, DobuleAnimation. ( Timer Tick):
Random random = new Random();
Bomb bomb = new Bomb();
bomb.IsFalling = true;
var easefall = new QuadraticEase();
easefall.EasingMode = EasingMode.EaseIn;
var randNumber = random.Next(0, 100);
if (randNumber < 15)
{
bomb.Scale.ScaleX = bomb.Scale.ScaleY = 0.8;
Canvas.SetZIndex(bomb, 1);
}
bomb.SetValue(Canvas.LeftProperty, (double)(random.Next(0, (int)(canvasBackground.ActualWidth - 30))));
bomb.SetValue(Canvas.TopProperty, -200.0);
bomb.ManipulationStarted += bomb_ManipulationStarted;
Storyboard storyboard = new Storyboard();
DoubleAnimation fallAnimation = new DoubleAnimation();
fallAnimation.To = canvasBackground.ActualHeight;
fallAnimation.Duration = TimeSpan.FromSeconds(m_secondsToFall);
fallAnimation.EasingFunction = easefall;
StoryBoardHelper.SetTarget(fallAnimation, bomb);
Storyboard.SetTargetProperty(fallAnimation, new PropertyPath("(Canvas.Top)"));
storyboard.Children.Add(fallAnimation);
DoubleAnimation wiggleAnimation = new DoubleAnimation();
wiggleAnimation.To = 40;
wiggleAnimation.Duration = TimeSpan.FromSeconds(0.3);
wiggleAnimation.RepeatBehavior = RepeatBehavior.Forever;
wiggleAnimation.AutoReverse = true;
var easewiggle = new CircleEase();
easewiggle.EasingMode = EasingMode.EaseInOut;
wiggleAnimation.EasingFunction = easewiggle;
StoryBoardHelper.SetTarget(wiggleAnimation, ((TransformGroup)bomb.RenderTransform).Children[0]);
Storyboard.SetTargetProperty(wiggleAnimation, new PropertyPath("Angle"));
storyboard.Children.Add(wiggleAnimation);
canvasBackground.Children.Add(bomb);
m_storyboards.Add(bomb, storyboard);
storyboard.Duration = fallAnimation.Duration;
storyboard.Completed += storyboard_Completed;
storyboard.Begin();
, /. :
private void bomb_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
FrameworkDispatcher.Update();
Bomb bomb = (Bomb)sender;
bomb.IsFalling = false;
Storyboard storyboard = m_storyboards[bomb];
double currentTop = Canvas.GetTop(bomb);
storyboard.Stop();
m_beep.Play();
storyboard.Children.Clear();
DoubleAnimation riseAnimation = new DoubleAnimation();
riseAnimation.From = currentTop;
riseAnimation.To = 0;
riseAnimation.Duration = TimeSpan.FromSeconds(2);
StoryBoardHelper.SetTarget(riseAnimation, bomb);
Storyboard.SetTargetProperty(riseAnimation, new PropertyPath("(Canvas.Top)"));
storyboard.Children.Add(riseAnimation);
DoubleAnimation slideAnimation = new DoubleAnimation();
double currentLeft = Canvas.GetLeft(bomb);
if (currentLeft < canvasBackground.ActualWidth / 2)
{
slideAnimation.To = -100;
}
else
{
slideAnimation.To = canvasBackground.ActualWidth + 100;
}
slideAnimation.Duration = TimeSpan.FromSeconds(1);
StoryBoardHelper.SetTarget(slideAnimation, bomb);
Storyboard.SetTargetProperty(slideAnimation, new PropertyPath("(Canvas.Left)"));
storyboard.Children.Add(slideAnimation);
storyboard.Duration = slideAnimation.Duration;
storyboard.Begin();
}
PS: Silverlight:)