Animating your skin
1 About Skin Animations
The XBMC skin engine has support for animations between control and window states. The animations are defined through use of the <animation> tag, which has a defined type and various attributes that specify the animation to be performed. All animations are additive – if two of them are in effect at the same time, their effects are added together. Note that you may only have one animation of each type however.
1.1 Window Animations
There are two valid window animation – the animation to perform when the window is opened, and the animation to perform when the window is closed. They take the same format as the control animations.
1.2 Control Animations
There are 6 valid control animations: WindowOpen, WindowClose, Visible, Hidden, Focus, and Unfocus. There is also a combination animation VisibleChange that constructs the Visible animation, then reverses it for the Hidden animation.
1.3 Format of Animation Tags
The animation tag is formatted as follows: <xml> <animation attributes>type</animation> </xml>
The type can be one of the following:
- Performed once only when the window is opened.
- Performed once only when the window is closed. No animation is performed when switching to fullscreen video, however. Visible Performed when the control becomes visible via its <visible> tag.
- Performed when the control becomes hidden via its <visible> tag.
- Performed when the control gains focus.
- Performed when the control loses focus.
- The same as the Visible type, except the reverse animation is auto-created for the Hidden type. Just saves having to have both animations if the animation is the same in both directions (ie just reversed)
The attributes available are as follows. Note that all attributes, like tags, are case sensitive
- Specifies the effect to use. Currently “fade”, “slide”, “rotate”, and “zoom” are supported.
Specifies the length of time that the animation will run, in milliseconds.
- The time to delay the transistion before starting it, in milliseconds.
- The start state of the control for this transistion. For fades, this is the opaqueness as a percentage (ie start="100" is fully opaque, start="0" is fully transparent. For slides, this is the relative coordinate offset to start the control at (ie start="50,60" will start the control off at 50 pixels to the right, and 60 pixels below it's normal viewing position. For rotates, this is the starting degree offset from the horizontal. (ie start="30" will start the control off on an angle of 30 degrees from the horizontal). For zooms, this is the starting size as a percentage. (ie start="50,60" will start the control at 50% of it's horizontal size and 60% of it's vertical size).
- The end state of the control for this transistion. Similar to the start state, except that the end state is always kept after the animation is finished, and until the control changes its state.
- Amount to accelerate or decelerate during a “slide”, “zoom” or “rotate” transistion. For deceleration, use a negative value. A value of -1 will cause the control to come to rest at its end coordinates. Defaults to 0.
- Center of the rotation or zoom to perform with a “rotate” or “zoom” transistion. This is the coordinates about which the rotation or zoom will take place. eg center="30,50” will mean that all points will revolve around (or zoom from) the (30,50) pixel location.
- The conditions under which this animation should be performed. Defaults to being always performed. See here for a list of valid conditionals.
- If “false” the animation is not reversed if it is interrupted when it is finished. For instance a Visible animation will normally be reversed (instead of running the Hidden animation) if the control becomes hidden before the visible animation has finished. Setting reversible="false” prevents this behaviour (the Hidden animation will take its place). Defaults to true.
<xml> <visible>Player.HasAudio</visible> <animation effect="fade" time="400">VisibleChange</animation> </xml>
This causes XBMC to fade the control in 400 milliseconds between the visible and hidden states. The control will start off hidden, and will fade in over 400ms when you play audio, and when it's finished, it will fade out again over 400ms.
You can also specify different transistion times for transistioning in and out as follows:
<xml> <animation effect="fade" time="100">WindowOpen</animation> <animation effect="fade" time="100">WindowClose</animation> </xml>
This, when used as the animation tag for the ~MusicOSD dialog, will cause it to fade in quickly (in 100ms) when activated and the fade out again slowly (in 1 second (1000ms)) when it's cancelled.
You can also specify that a control should always fade in when the window is opened by using
<xml> <animation effect="fade" time="200">WindowOpen</animation> </xml>
This specifies that it will always start hidden, but will fade in immediately (over a time of 200ms) when the window is opened.
There is also ability to add delays preceding the transistions. For instance
<xml> <animation effect="fade" time="200" delay="200">Hidden</animation> </xml>
would mean that the control will fade out after a delay of 200ms. This is useful for "crossfade" effects, where you want the new control to fade in while the old control is still on screen (and then fade the old one out once the new one is completely opaque).
There are also slide effects available.
<xml> <animation effect="slide" end="30,0" time="200">Focus</animation> </xml>
will slide the control 30 pixels to the right of its normal position when it becomes focused. Note that when it becomes unfocused it will jump back to it's normal position. A Unfocus animation will make it slide back gracefully.
There are also rotate effects available.
<xml> <animation effect="rotate" end="30" center="360,288" time="200">Focus</animation> </xml>
will rotate the control 30 degrees counter clockwise about the center of a PAL screen (360,288) when the control becomes focused.
And we also have zoom effects.
<xml> <animation effect="zoom" end="120" center="360,288" time="200">Focus</animation> </xml>
will zoom the control to 120% of its normal size when the control becomes focused, with the zoom centered at the center of a PAL screen (360,288). You can zoom each dimension by different amounts (effectively a stretch operation) as well. To stretch a control an extra 50% horizontally when focused, we can use
<xml> <animation effect="zoom" end="150,100" center="360,288" time="200">Focus</animation> </xml>
An example of a conditional animation is:
<xml> <animation effect="slide" start="-120,0" time="200" condition="Window.Previous(Home)">WindowOpen</animation> </xml>
This will cause the slide animation to only be performed if you are coming to this window from the Home window.