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>
/// chap05.xaml 的交互逻辑
/// </summary>
public partial class chap05 : Window
{
public chap05()
{
InitializeComponent();
DrawPlayer();
DispatcherTimer dispatcherTimer = new DispatcherTimer(DispatcherPriority.Normal);
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = TimeSpan.FromMilliseconds(150);
dispatcherTimer.Start();
}
void dispatcherTimer_Tick(object sender, EventArgs e)
{
player.Source = new CroppedBitmap(bitmapFrame, new Int32Rect(count * 150, 0, 150, 150));
count = (count == 9 ? 0 : ++count);
}
private void DrawPlayer()
{
player = new Image();
player.Width = 150;
player.Height = 150;
container.Children.Add(player);
}
private Image player;
private int count = 0;
private BitmapFrame bitmapFrame = BitmapFrame.Create(new Uri(@"Player\PlayerMagic.png", UriKind.Relative));
}
}
WPF游戏编程--2D人物动画
最新推荐文章于 2019-08-14 11:29:09 发布