
These articles illustrate a mechanism you can use to perform sophisticated animations using WPF without needing to make your code overly complex while still adapting to the two key constraints WPF imposes on animation development. The first is explicit, a requirement that manipulation of any display property of a visible object take place on the thread that originally created the object. The second is implicit, the animations themselves are event driven, and therefore the application must be idle in order for animations to execute.
The large body of examples of WPF animations deal with simple 2D animations where the entire animation sequence is known in advance, e.g. animations that cause buttons to gradually change color as the mouse moves over them and away again. The goal of these articles is to illustrate more sophisticated 3D animations, where the entire animation state is not known in advance, but must be worked out by active logic during the animation sequence itself.
For simple visual interest, these examples all center on the Chinese game of Mah-Jongg. While these techniques are equally applicable to any number of western card games, I feel that Mah-Jongg adds a certain visual interest to the examples, and some issues, glossed over in these articles will be dealt with in later articles. Full source code to the Mah-Jongg implementation is provided here, however it should be noted that this code is a vehicle for a family of articles, it isn’t meant as a reference implementation of Mah-Jongg. At present, the code is capable of nicely animating the initial setup and deal of a Mah-Jongg game, after which it will sit there stupidly until it is shut down. I expect it will probably continue to evolve, but as to whether it will grow up to be a full game, who knows. Mah-Jongg is a complex game, so it is questionable.
The articles in this series are laid out in the following order.
Introduction This article explains the requirements involved in converting a bag of MJ tiles into a physically organized set of tiles representing the layout of the game at the start of play. The process of moving from this bag of random tiles to a laid out board with all hands dealt is a complex animation, where subsequent steps depend on the results of previous steps, and therefore serves as an excellent vehicle for demonstrating the applicable concepts. The article also provides background and references to the continuation implementation pattern, which lies at the heart of the solution to this problem.
Animation Breakdown This article decomposes the entire animation into a set of independent steps, each of which can be realized by an atomic animation sequence. It shows how continuations are used to move from step to step.
Animation Sequencing One powerful capability that arises from this implementation pattern is the ability to drive multiple virtual threads of control, each associated with an independent animation sequence. This article digs into the ramifications of this, and shows how control flows can split apart and merge, and how it is possible to integrate logical structures that control branching and looping in these control flows.
Animation Mechanics This article examines the detailed mechanics of the animations, and provides the greatest level of detail on exact usage of WPF animations. These examples all concentrate on procedurally defined keyframe animations, and this article shows exactly how they are created, manipulated, and executed.