C # development Wpf/silverlight animation and games series Tutorials (Game Course): (d)

Source: Internet
Author: User
Tags count silverlight

C # development Wpf/silverlight animation and game series Tutorials (Game Course): (iv) to achieve 2D character animation ①

In the previous study, we have mastered how to create objects moving animation dynamically, then I will explain how WPF in the 2D game role, and by using the DispatcherTimer timer described above to achieve the 2D characters of the various action animation.

The dynamic implementation of the 2D character animation currently has two mainstream methods, I will introduce the following separately.

The first method I call the picture switching method, preparation: First through the 3DMAX tools 3D rendering 2D method to create the role, and then the role of each action are exported in 8 directions in each direction a number of frames of the picture (if it is a directional magic picture, Many 2D-MMORPG tend to export a series of 16-direction frames in order to be more realistic, each of the characters in each direction of each frame will be saved into a picture, the following figure only from the broken-day sword game extracted material as an example:

(Special note: This series of tutorials used in the ownership of the picture materials are derived from the network, do not use for commercial purposes, otherwise caused by all the consequences have nothing to do with me.) )

As you can see from the picture above, I'm going to run the characters to the right a total of 8 frames of images by Photoshop to enlarge the canvas to 150*150 pixel image (because it is the extracted material, the initial width and height is an unbalanced value, so must be enlarged into their own needs, so that people will be in the and leave room for the late addition of weapons or mounts. A slight deviation can also be fine-tuned at a later stage), And they are named 0.png,1.png,2.png,3.png,4.png,5.png,6.png,7.png from the beginning to the end (and incidentally, the best picture background alpha transparent, otherwise in the algorithm to go to color, is not superfluous?) As for why PNG instead of GIF, I take into account that Silverlight currently only supports PNG and JPG, for more versatility, of course, if you only use Wpf,gif or PNG. Finally in the project we create a new folder named Player, and then save the 8 pictures in the directory, to the end of the preparation, daze. It's really tiring.

Next is the play, how to achieve the dynamic creation of the character movement animation through Pure C #? Hey, and look at the code below.

int count = 1;
        Image Spirit;
        Public Window4 () {
            InitializeComponent ();
            Spirit = new Image ();
            Spirit.width =;
            Spirit.height =;
            CARRIER.CHILDREN.ADD (Spirit);
            DispatcherTimer DispatcherTimer = new DispatcherTimer ();
            Dispatchertimer.tick + = new EventHandler (Dispatchertimer_tick);
            Dispatchertimer.interval = Timespan.frommilliseconds ();
            Dispatchertimer.start ();
        }
        private void Dispatchertimer_tick (object sender, EventArgs e) {
            spirit.source = new BitmapImage (The new Uri (@ "Player\" + Count + ". png", urikind.relative));
            Count = Count = 7? 0:count + 1;
        }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.