I have an ellipse, and I want to make an animation to show this ellipse.
The animation should do something like this gif:
http://media.giphy.com/media/qiutE2wCo1YXe/giphy.gif
But instead of the ellipse disappear, it starts from zero and ends full.
Does anybody can help me with this?
You can make it by splitting the ellipse in half and animate two pieces of it separately. Here's my solution that implements the idea.
First of all, you have to define shapes to animate. I use Canvas as a container.
<Canvas Width="100"
Height="100">
<Canvas.Clip>
<EllipseGeometry RadiusX="50"
RadiusY="50"
Center="50, 50" />
</Canvas.Clip>
<Canvas>
<Canvas.Clip>
<RectangleGeometry Rect="0, 0, 50, 100" />
</Canvas.Clip>
<Rectangle x:Name="HalfLeft"
Width="50"
Height="100"
Fill="Red"
Canvas.Left="0"
Canvas.Top="0">
<Rectangle.RenderTransform>
<RotateTransform Angle="-180"
CenterX="50"
CenterY="50"/>
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
<Canvas>
<Canvas.Clip>
<RectangleGeometry Rect="50, 0, 50, 100" />
</Canvas.Clip>
<Rectangle x:Name="HalfRight"
Width="50"
Height="100"
Fill="Red"
Canvas.Left="50"
Canvas.Top="0">
<Rectangle.RenderTransform>
<RotateTransform Angle="-180"
CenterX="0"
CenterY="50"/>
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
</Canvas>
You can modify Angle value to see how it works. I set -180 degrees, so they are invisible, but the angle will be animated to 0.
Then you need two animations in one storyboard. I have added it to main page resources.
<phone:PhoneApplicationPage.Resources>
<Storyboard x:Name="FillAnimation">
<DoubleAnimation Storyboard.TargetName="HalfLeft"
Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
From="-180"
To="0"
BeginTime="00:00:01"
Duration="00:00:01"/>
<DoubleAnimation Storyboard.TargetName="HalfRight"
Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
From="-180"
To="0"
Duration="00:00:01"/>
</Storyboard>
</phone:PhoneApplicationPage.Resources>
And that's it. The last thing you have to do is to run the animation from code.
FillAnimation.Begin();
Screenshot:
Related
I have a LinearGradientBrush and am trying to apply the RotateTransform offset to it. With this code, it rotates and keeps still at the angle I give it:
<LinearGradientBrush.Transform>
<RotateTransform CenterX="60" CenterY="30" Angle="45" />
</LinearGradientBrush.Transform>
Is there a way to make the "Angle" dynamic so the brush will spin at 180 degrees?
You can run a DoubleAnimation on the Angle property of the RotateTransform, like in the example below, where the LinearGradientBrush fills a Rectangle, and the the animation is started when the Rectangle is loaded, and then runs forever:
<Rectangle Width="300" Height="300">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="Black" Offset="1"/>
<LinearGradientBrush.Transform>
<RotateTransform CenterX="150" CenterY="150"/>
</LinearGradientBrush.Transform>
</LinearGradientBrush>
</Rectangle.Fill>
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Fill.Transform.Angle"
To="360" Duration="0:0:5" RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
I don't know how to cut center of element (do center of element clear [sorry for my english]). I think to use opacity mask but i can't create this. I need create like this
<Rectangle Fill="#FFFF0000" Height="100" Width="100" />
<Rectangle Fill="#FF00FF00" Height="100" Width="100">
<Rectangle.OpacityMask>
<ImageBrush Stretch="Fill" ImageSource="mask.png"/>
</Rectangle.OpacityMask>
</Rectangle>
I am developing a Windows Phone 8 game application and I want to rotate the image and at the same time I want to re-size the image from 100 to 0 then again from 0 to 100. Till now what I have done is
<Storyboard x:Name="Rotatetransition" >
<DoubleAnimation Storyboard.TargetName="TransRotate"
Storyboard.TargetProperty="ScaleX"
From="1" To="0"
BeginTime="0:0:0"
Duration="0:0:0.5"
AutoReverse="True"/>
<DoubleAnimation Storyboard.TargetName="TransRotate"
Storyboard.TargetProperty="ScaleY"
From="1" To="0"
BeginTime="0:0:0"
Duration="0:0:0.5"
AutoReverse="True"/>
</Storyboard>
So this animation is resizing my image to 0 from 100. Now the same image I want to rotate so that it will look good and I can load new image for a new game.
For rotaing the image I have code
<Storyboard x:Name="Rotatetransition2" >
<DoubleAnimation Storyboard.TargetName="AnimatedRotateTransform"
Storyboard.TargetProperty="Angle"
By="10"
To="720"
Duration="0:0:0.2"
FillBehavior="Stop" />
</Storyboard>
But the problem is in the Image control I can use only one child <Image.RenderTransform>
<Image x:Name="PreviewImage" Height="480" Width="480" Opacity="1" RenderTransformOrigin="0.5,0.5" >
<Image.RenderTransform>
<ScaleTransform x:Name="TransRotate" />
</Image.RenderTransform>
<!--<Image.RenderTransform>
<RotateTransform x:Name="AnimatedRotateTransform" Angle="0" />
</Image.RenderTransform>-->
</Image>
In the code behind when the game completes I will call
Rotatetransition.Begin();
Circletransition.Begin();
RotatetransitionRev.Begin(); // Again resize the new Loaded image from 0 to 100
Circletransitionrev.Begin(); // Roate the image again from 0 to 720
StartThegame();
Can anyone suggest how do I achieve this?
and the new game will start.
Try using a TransformGroup:
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform />
<RotateTransform />
</TransformGroup>
</Image.RenderTransform>
I am looking at the shapes available in Blend Expression 4 for my WP7 app I am making. I am a bit confused though how to add text to a shape.
How do I add text to a shape?
Shapes in Blend for WP7 are simply ... Shapes.
All Expression Shapes inherits from Path, that inherit from System.Windows.Shapes.Shape. Shape is a base class for creating graphics. It supports only very basics properties such as fill, stroke, transform, ... you can not add text inside a shape because it's a pure-graphical object.
Hopefully for you, because they derive from UIElement, shape objects can be used inside panels and most WP controls. The Canvas panel is a particularly good choice for creating complex drawings because it supports absolute positioning of its child objects.
So, two examples can be
<Grid>
<es:RegularPolygon Fill="#FFF4F4F5" Height="100" InnerRadius="1" PointCount="6" Stretch="Fill" Stroke="Black" Width="100" />
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="Hello" Foreground="black"/>
</Grid>
or
<Canvas Height="200" Width="200">
<es:RegularPolygon Canvas.Left="50" Canvas.Top="50" Fill="#FFF4F4F5" Height="100" InnerRadius="1" PointCount="6" Stretch="Fill" Stroke="Black" Width="100" />
<TextBlock Canvas.Left="75" Canvas.Top="85" VerticalAlignment="Center" HorizontalAlignment="Center" Text="Hello" Foreground="black"/>
</Canvas>
I have the following which works for animating the opacity of the image, but what I'd really like to do is have the image move back in forth say 100 pixels to the right then a 100 pixels to the left. But I haven't been able to achieve this effect.
<Image Source="MyImage.jpg" Width="2000" Height="800" x:Name="MyAnimatedImageGeometry">
<Image.Triggers>
<EventTrigger RoutedEvent="Image.Loaded">
<BeginStoryboard>
<Storyboard Storyboard.TargetName="MyAnimatedImageGeometry" Storyboard.TargetProperty="Opacity">
<DoubleAnimation To="0" AutoReverse="True" RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
Here's an image:
<Image x:Name="image" Source="/filename.png" RenderTransformOrigin="0.5,0.5" >
<Image.RenderTransform>
<CompositeTransform TranslateX="0"/>
</Image.RenderTransform>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<eim:ControlStoryboardAction Storyboard="{StaticResource moveImage}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Image>
The initialization of the rendor transform is the interesting bit. The trigger is just there to demonstrate starting the storyboard. You wouldn't do this in a real app as tapping the item to move it in this way gets messed up when you tap it while it's moving. (Obviously this would be easy to control in code.)
Here's the other interesting bit, the related storyboard:
<Storyboard x:Name="moveImage" AutoReverse="True" RepeatBehavior="1x">
<DoubleAnimation Duration="0:0:1"
To="-100"
Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)"
Storyboard.TargetName="image"
<DoubleAnimation.EasingFunction>
<CubicEase EasingMode="EaseIn"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
This will move the image 100 pixels to the left (over a period of one second) and then back again.
I've added an easing function to make it more interesting.