WPF游戏编程--2D人物动画

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace WPFApplication
{
    /// <summary>
    /// chap04.xaml 的交互逻辑
    /// </summary>
    public partial class chap04 : Window
    {
        public chap04()
        {
            InitializeComponent();

            InitPlayer();

            DispatcherTimer dispatcherTimer = new DispatcherTimer(DispatcherPriority.Normal);
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(150);

            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);

            dispatcherTimer.Start();
        }

        void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            player.Source = new BitmapImage(new Uri(@"Player\" + count + ".png", UriKind.Relative));

            count = ((count == 7) ? 0 : ++count);
        }

        private void InitPlayer()
        {
            player = new Image();
            player.Width = 150;
            player.Height = 150;

            container.Children.Add(player);
        }


        private Image player;
        private int count;
    }
}


你可能感兴趣的:(WPF游戏编程--2D人物动画)