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

Source: Internet
Author: User
Tags relative silverlight

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

The second method I call the picture interception method, prepares to work: Here I create the protagonist to the right direction to cast the animation as an example. First of all, you need to 150*150 10 frames of the picture through Photoshop or other ways to become a 1500*150 big picture, the following figure:

It is clear from the diagram that the main character's entire flow of the casting process. Then save the picture to the Bindebug folder in the project folder, as shown in the following figure:

Why do we have to put it here? Because the Bitmapframe.create () function calls the relative path picture in the following code to only recognize the folder, why? Ask MS

Ok,xaml code is still the same as in the previous chapters, then the following is the background C # code:

Image Spirit;
        int count = 1;
            Public Window5 () {InitializeComponent ();
            Spirit = new Image ();
            Spirit.width = 150;
            Spirit.height = 150;
            CARRIER.CHILDREN.ADD (Spirit);
            DispatcherTimer DispatcherTimer = new DispatcherTimer ();
            Dispatchertimer.tick + = new EventHandler (Dispatchertimer_tick);
            Dispatchertimer.interval = Timespan.frommilliseconds (150);
        Dispatchertimer.start (); } private void Dispatchertimer_tick (object sender, EventArgs e) {spirit.source = Cutimage (@ "PLAYER\PL
            Ayermagic.png ", Count * 150, 0, 150, 150); Count = Count = 9?
        0:count + 1; ///<summary>///intercepting pictures///</summary>///<param name= "imgaddress" > FileName (including address + extension) </param>///<param name= "x" > upper left corner x</param>///<param name= "y" > upper left corner y< /param>///<paramName= "width" > Captured picture width </param>///<param name= "height" > truncated picture high </param>///&LT;RETURNS&G 
            t; After intercepting image data source </returns> private BitmapSource cutimage (string imgaddress, int x, int y, int width, int height) { 
                return new Croppedbitmap (Bitmapframe.create (imgaddress, urikind.relative)),
  New Int32Rect (x, y, width, height)); }

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.