您的位置:首页 > 编程语言

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

2011-10-11 19:40 357 查看
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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐