Jump to content

Featured Replies

Posted
  • FPCH Admin

Fast and fluid animations bring apps to life. In Windows 8 Consumer Preview, you will notice that animations are an integral part of the user experience. When you log in to your PC, the items in the Start menu animate in. When you launch an immersive app or zoom into the Start menu, the experience is enriched with a smooth animation. Animations can tell the user what happened as a result of a specific action. This visual feedback instills user confidence in the app’s responsiveness. Even a simple addition or deletion of an item in a list can be made fluid, modern, and informative using a subtle animation (as seen in  Your browser doesn't support HTML5 video. [/b]

Download this video to view it in your favorite media player:

[url=http://media.ch9.ms/ch9/659d/0fc45493-3b60-4a49-82c5-014fe8f8659d/FastAndFluid_high.mp4">High quality MP4 | [url=http://media.ch9.ms/ch9/659d/0fc45493-3b60-4a49-82c5-014fe8f8659d/FastAndFluid.mp4">Lower quality MP4 In Windows 8, animations are a key component of the Metro style personality and you can bring this personality to your own apps! Here is what’s in this blog post:

  • A brief overview of the animation engine
  • How to get started using the Animation Library
  • Custom animations and how to take advantage of the animation engine improvements
  • Tips ‘n tricks for incorporating animations in your Metro style apps.

Independent animation A big part of the Windows 8 experience is smooth and glitch-free animations, which are achieved through a capability called independent animation. An independent animation is an animation that runs independently from thread running the core UI logic. (A dependent animation runs on the UI thread.) In Windows 8 many of the animated elements are composed by a composition engine that runs on a separate thread. The engine’s work is offloaded from the CPU to the GPU. Moving composition to a non-UI thread means that the animation won’t jitter or be blocked by the app working on the UI thread (such as JavaScript code execution or sync operations). The GPU hardware is optimized for delivering visually rich graphics and makes use of video memory resources. Using the GPU greatly improves performance, allowing animations to run at a smooth and consistent frame rate. You don’t need additional markup to make your animation take advantage of the independent animation capability. The system determines when it is possible to compose the animation independently. To make animations in your apps performant and smooth, you need to follow the independent Animation Library[/size] The [url=http://msdn.microsoft.com/en-us/library/windows/apps/hh465165.aspx" target="_blank">Animation Library is a suite of Metro style animations that has been built specifically to take advantage of the platform’s independent animation capability. These animations are used throughout Windows UI and are also available for your Metro app. Think of this library as providing a palette of animations that do the right thing for you and are already designed to be fast and fluid. As app developers ourselves, we love this feature because we don’t have to spend time creating animations that have the Windows 8 look and feel. Simply use the Animation Library and your app now is part of the Windows experience. This library animates the Windows UI itself. These animations are clean and purposeful. We put a lot of attention into getting the timing and animation curves exactly right so that the user gets fast and fluid feedback when they interact with the Windows UI. So when designing animations in your app, we recommend that you first look at the Animation Library to find the best animation that fits your need. It doesn’t matter if you are using HTML or XAML, the Animation Library provides you with a way to use the right animations and ensures that your UI will be fast and fluid. Let’s look at some examples.

JavaScript example

The JavaScript/HTML Personality Library is built with CSS3 animations and transitions. These animations are used for app navigation, content transitions and Windows 8 controls. A simple yet compelling animation is the [url=http://msdn.microsoft.com/en-us/library/windows/apps/br212672.aspx" target="_blank">EnterPage animation. Use it when displaying content for the first time or transitioning between pages in a running app. This example demonstrates how you can use this simple API in your app.

HTML

 

CSS

 

 

JavaScript

 

 

XAML example

 

In XAML, the built-in Animation Library entails two concepts: Theme transitions and theme animations.

 

Theme transitions are typically used to animate visuals on the screen as they are loading, unloading or changing location on the screen. XAML layout system triggers these built-in animations in response to changes in the layout of the page.

 

These layout triggers include:

 

 

A particular theme transition may respond to any or all of the layout triggers. The EntranceThemeTransition responds to trigger #1 and animates UIElements as they are added to the page or visual tree. In the next example, all of Grid’s children are animated using EntranceThemeTransition.

 

 

Theme animations are built-in animations that are typically run on user interaction and you must trigger them to run. The easiest way to run a theme animation is to call the Begin method on Storyboard class. If you are familiar with the Begin[/b] method:

 

XAML

 

 

Code

 

 

Custom animations

 

As powerful as the Animation Library is, it can’t cover all your scenarios. For such cases, you can build your own custom animations that the system runs independently (see [url=http://msdn.microsoft.com/en-us/library/windows/apps/hh849087.aspx" target="_blank">Animating for design guidance on building your own animations). This is where you need to be more careful about how to build an animation so that it doesn’t end up running on the UI thread.

 

You can still use dependent animations in your app. We encourage you to follow the independent animation guidance for custom animations but if your scenario requires animations that cannot be independently animated then the animation can still be run dependently.

 

The examples here demonstrate the use of a 3D non-affine independent animation that is not in the Animation Library.

 

JavaScript

 

For JavaScript apps, you can access the independent animation capability for custom animations via the CSS3 [url=http://msdn.microsoft.com/en-us/library/windows/apps/hh441191.aspx" target="_blank">Animation and [url=http://msdn.microsoft.com/en-us/library/windows/apps/hh453384.aspx" target="_blank">Transition syntax newly introduced to the Microsoft web platform in IE10. Independent animation supports only properties that don’t require re-layout or re-rendering. That means, independent animation for JavaScript apps is applicable to and supported only for CSS Animations/Transitions that target CSS3 2D and 3D [url=http://msdn.microsoft.com/en-us/library/windows/apps/hh453377.aspx" target="_blank">Transforms or [url=http://msdn.microsoft.com/en-us/library/windows/apps/ff972268.aspx" target="_blank">Opacity. Animations of other CSS properties run dependently on the UI thread.

 

Example of HTML custom animation

 

The example here demonstrates a simple CSS 3D flip.

 

HTML

 

 

<a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh849087.aspx%22%20target=%22_blank%22%3Eanimation%20guidelines%20in%20the%20Dev%20Center.%20These%20guidelines%20are%20most%20useful%20when%20creating%20custom%20animations,%20which%20we'll%20dive%20into%20later%20in%20this%20post.%20%20%20Now,%20let%E2%80%99s%20get%20started%20with%20learning%20how%20you%20can%20enhance%20your%20apps%20by%20first%20making%20use%20of%20the%20metro-style%20animations%20that%20are%20provided%20in%20the%20Animation%20Library.%20%20%5Bsize=5" rel="external nofollow"><a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.visualstatemanager.aspx%22%20target=%22_blank%22>VisualStateManager%20(VSM),%20a%20theme%20animation%20can%20be%20put%20inside%20a%20visual%20state%20of%20a%20control.%20This%20example%20shows%20how%20to%20trigger%20a%20theme%20animation%20using%20the%20%5Bb" rel="external nofollow">Html animations CSS3</a></a>

 

CSS

 

 

XAML

 

For XAML apps, a specific subset of properties are supported independently (you can find more info in the Windows 8 Developer Center). These properties include canvas positioning, opacity, render transforms, projections, clips and color.

 

Animating any property, besides the list we just looked at, results in a dependent animation. Meaning, the animation runs on the UI thread and thus will be at a risk of glitching. To encourage the development of fast and fluid UI XAML runs only independent animations unless you explicitly enable dependent animations. If you want to run a dependent animation, you can use the EnableDependentAnimation property on Timeline. There’s also a global static AllowDependentAnimations property that you can set to false to disable all dependent animations in your app.

 

Example of a XAML custom animation

 

The next example shows how to animate properties on PlaneProjection that the system runs independently. The animation concepts and syntax are exactly the same as in other XAML technologies but have been enhanced in Windows 8 to run independently, resulting in better performance characteristics for apps.

 

 

 

 

 

Best practices for independent animations

 

As with all systems, there are some limitations for independent animation. These limitations are different for the HTML and XAML platforms. In general you get independent animations except for these cases:

 

 

Here are a few guidelines for independent animations.

 

JavaScript

 

 

XAML

 

 

In closing

 

We are excited about the fast and fluid user experiences that independent animation enables for Windows 8 apps. We hope that you find the Animation Library and the support for custom animations that run independently of the UI thread useful when you create compelling user experiences in your Metro style apps for Windows 8.

 

-- Angelina Gambo and Hamid Mahmood

 

    Program Managers, Windows7ae5489801c6ebe19a4218f07536c491._.gif

 

View the full article

Edited by AWS

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...