0

This is my code in c# microsoft visual studio windows phone. My application is all about "SPIN THE BOTTLE", unfortunately, it spins fast but never slows down while near in stopping, it just stop then that's it. Can anyone pls. help me? How to have this app have a realistic motion of a bottle from fast to slow stopping?

Random random = new Random(); //Declare random
int randomNumber = random.Next(7201, 7560);
Duration Time_duration = new Duration(TimeSpan.FromSeconds(2)); 
Storyboard MyStory = new Storyboard();
MyStory.Duration = Time_duration;
DoubleAnimation My_Double = new DoubleAnimation();
My_Double.Duration = Time_duration;
MyStory.Children.Add(My_Double);
RotateTransform MyTransform = new RotateTransform();
Storyboard.SetTarget(My_Double, MyTransform);
Storyboard.SetTargetProperty(My_Double, new PropertyPath("Angle"));
My_Double.To = randomNumber;
image1.RenderTransform = MyTransform;
image1.RenderTransformOrigin = new Point(0.5, 0.5);
MyStory.Begin();
PhilMY
  • 2,621
  • 21
  • 29
  • This is easier done in XAML with Expression Blend, if you have access to it. You can try a free trial for a couple of months, I believe. I'll post a code solution below. – cunningdave Jul 21 '12 at 14:41

1 Answers1

0

You want to change the Easing Function of your animation. Here's an example:

    <Storyboard x:Name="SpinBoxStory">
        <DoubleAnimation Duration="0:0:2" To="1375.909" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="rectangle" d:IsOptimized="True">
            <DoubleAnimation.EasingFunction>
                <QuarticEase EasingMode="EaseOut"/>
            </DoubleAnimation.EasingFunction>
        </DoubleAnimation>
    </Storyboard>

Easing Functions are described here. I picked one that would have similar properties to a bottle spinning and slowing down due to ground friction.

In your example, you just want to create a new QuarticEase and assign it to your My_Double animation.

cunningdave
  • 1,470
  • 10
  • 13