700 likes | 969 Vues
Principles of Microsoft Silverlight Animation. Jeff Paries Sr. Experience Developer Waggener Edstrom Worldwide Author: Foundation Silverlight 2 Animation. Shameless Plug. “This book is easily worth ten times the money. I haven't seen a better book about animation in Silverlight yet.”
E N D
Principles of Microsoft Silverlight Animation Jeff Paries Sr. Experience Developer Waggener Edstrom Worldwide Author: Foundation Silverlight 2 Animation
Shameless Plug “This book is easily worth ten times the money. I haven't seen a better book about animation in Silverlight yet.” - MaciejMisztal, Amazon.com “The descriptions of how it works and WHY to do something a certain way are priceless. I had several "Oh, now I get it" reactions over the course of reading this book.” - Speednet, Amazon.com “My best reviews are reserved for books that teach the material well and completely. This is the best of the books on Silverlight that I've purchased. It rates five stars in my world.” - Robin T. Wernick, Amazon.com
Session Topics • Storyboards, animations, and keyframes • Vectors • Frame-based animations • Particle systems • VR objects
Where Do Storyboards Come From? • <Storyboard x:Name="Storyboard1"/>
Where Do Storyboards Come From? • Are containers • Can contain many animations • Can be left empty (used as timers) • <Storyboard x:Name="Move" Duration="00:00:00"/> • Can also be created in code
Where Do Animations Come From? • <Storyboard x:Name="Storyboard1"> • <DoubleAnimationUsingKeyFrames • BeginTime="00:00:00" • Storyboard.TargetName="ellipse" • Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"> • <SplineDoubleKeyFrame KeyTime="00:00:01" • Value="370"/> • </DoubleAnimationUsingKeyFrames> • </Storyboard>
Where Do Animations Come From? • Are placed inside Storyboard containers • Used to change object properties over time • Animation types correspond to data types • Double (width, height, left, top, etc.) • Color (fill, stroke, etc.) • Point (for path manipulation) • Can also be created with code
Where Do Animations Come From? • Each animation type has two variations • From/to • UsingKeyframes
Where Do Keyframes Come From? • <SplineDoubleKeyFrame KeyTime="00:00:01" • Value="370"/>
Where Do Keyframes Come From? • There are three types of keyframes • Linear (linear movement between keyframes) • Spline (allows motion “easing”) • Discrete (holds an object until next keyframe) • Change type by right-clicking keyframe • “Ease in” or “Ease out” = Spline • “Hold in” = Discrete
Where Do Keyframes Come From? • <LinearDoubleKeyFrameKeyTime="00:00:01" Value="370"/> • <SplineDoubleKeyFrame KeyTime="00:00:01" Value="370"/> • <SplineDoubleKeyFrame KeyTime="00:00:01" Value="370" KeySpline="0,0,0.50,1"/> • <DiscreteDoubleKeyFrame KeyTime="00:00:01" Value="370"/>
Keyframe Types Linear Spline Discrete
Storyboard Animations Models Remixed Data Visualization
What's a Vector? • Are a key component of procedural animation • Describe direction and distance independent of time • Vector movement is simple – for each unit of time that passes, add the vector components to the object’s XY position
Vector Movement (1D) 0,0 +X X Velocity = 1 +Y LayoutRoot Canvas
Vector Movement (2D) 0,0 +X X Velocity = 1 Y Velocity = -2 +Y LayoutRoot Canvas
Changing Vector Direction 0,0 +X 5,-5 5,5 Multiply the Y component by -1 to reverse direction +Y LayoutRoot Canvas
Using vectors in C#Create/assign vector variables • private Point ObjPosition; • private double VelocityX = 1; • private double VelocityY = -2;
Using vectors in C#The event handler • privatevoidMove_Completed(objectsender, EventArgs e) • { • }
Using vectors in C#Update the object's position • ObjPosition.X += VelocityX; • ObjPosition.Y += VelocityY; • Canvas.SetLeft(MyObject, • ObjPosition.X); • Canvas.SetTop(MyObject, • ObjPosition.Y); • VelocityY += Gravity;
Using vectors in C#Restart the timer • Move.Begin();
Vector Animation Ball Drop
What is Frame-Based Animation? • Imitates original “flipbook” techniques • Accessible via • Storyboards • Visual State Manager • Code • Complex frame-based animation (i.e., characters) requires planning
What's a Sprite? • A 2D or 3D image or animation that becomes part of a larger scene • First used in the mid-70’s, still in use • Methods of producing sprite content • Rotoscoping live video (blue screen) • Claymation • 3D software • Vector artwork
Sprites with Discrete Keyframes • A series of images that depict the desired action • Images are aligned • Translated at some interval
Sprite Animation Dog Walk
Sprites with Visibility • Images are added in XAML
Sprites with Visibility • Use a storyboard to change frames
Sprite Animation Space Marine
Movement Flow ChartLinear • Goes directly from one move to another in a fixed order • Limits options (cannot Jump from Idle) Idle Walk Run Jump
Movement Flow ChartRadial • Less restrictive, but still limiting Jump Idle Walk Run
Movement Flow ChartDescending Idle Walk Run Jump Hit Get Hit (Run) (Idle) (Walk) (Jump) (Get Hit) Die
Movement Flow ChartCondescending Wife Boss Mother-in-Law Ex-Wife Dad Me
Sprite Animation Visual State Manager
Particle Systems • Often used to model “fuzzy” objects • Fire • Smoke • Explosions • Water
Basic Model for Particle System • For each unit of time that passes • New particles may be created • Old particles are conditionally removed • Existing particle positions are updated
What the Model Looks Like in C#The event handler • private void MoveParticles(object sender, EventArgs e) • { • }
What the Model Looks Like in C#Iterate through all available particles • for (inti = 0; i < • Particles.Count; i++) • { • }
What the model Looks Like in C#Update the position of the particle • Canvas.SetLeft(Particles[i], • Canvas.GetLeft(Particles[i]) + • Particles[i].Velocity.X); • Canvas.SetTop(Particles[i], • Canvas.GetTop(Particles[i]) + • Particles[i].Velocity.Y);
What the Model Looks Like in C#Update the particle age • Particles[i].Age += 1;
What the Model Looks Like in C#Evaluate age and act • if (Particles[i].Age >= • Particles[i].LifeSpan) • { • LayoutRoot.Children.Remove(Particles[i]); • Particles.Remove(Particles[i]); • CreateParticles(1); • }
What the Model Looks Like in C#Restart the timer • Move.Begin();