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

Source: Internet
Author: User
Tags count thread silverlight

C # development Wpf/silverlight animation and games series Tutorials (Game Course): (15) Wizard control turned out! Ii

Immediately following the previous section, we opened the QXSpirit.xaml.cs file. In the game design, in order to be able to easily control and manage the wizard's various properties and functions, I give each wizard a dedicated thread, which plays a key role in the use of the wizard:

public QXSpirit() {
 InitializeComponent();
 InitThread(); //初始化精灵线程
}
DispatcherTimer Timer = new DispatcherTimer();
private void InitThread() {
 Timer.Tick += new EventHandler(Timer_Tick);
 Timer.Start();
}
//精灵线程间隔事件
int count = 1;
private void Timer_Tick(object sender, EventArgs e) {
 Body.Source = new BitmapImage((new Uri(ImageAddress + count + ".png", UriKind.Relative)));
 count = count == 7 ? 0 : count + 1;
}

The creation of the DispatcherTimer thread is not too much to be seen in the previous chapters, and this is no longer a tiring statement. So why configure a thread in the wizard control? Make an analogy: we can compare the elf to be a person, its life is like this thread, each person has only one life, in the sperm and the egg after the combination (create the control initialization), life is beginning to live (after the creation of the start) simply say "Life hangs a line". Khan a .... Currently this thread is the same as in the previous chapter, temporarily only to do sprite action picture Cut (Timer_tick ()), as for other functions, I will explain in later chapters.

The

gives the elf life, then needs to cultivate its character, so that it has more power, more attributes. Of course, the first thing you want to achieve is the x,y attributes of the elves that were left over from the previous two sections. So first look at the code:

//精灵X坐标(依赖属性)
public double X {
 get { return (double)GetValue(XProperty); }
 set { SetValue(XProperty, value); }
}
public static readonly DependencyProperty XProperty = DependencyProperty.Register(
 "X", //属性名
 typeof(double), //属性类型
 typeof(QXSpirit), //属性主人类型
 new FrameworkPropertyMetadata(
 (double)0, //初始值0
 FrameworkPropertyMetadataOptions.None, //不特定界面修改
 //不需要属性改变回调
 null,//new PropertyChangedCallback(QXSpiritInvalidated),
 //不使用强制回调
 null
 )
);
//精灵Y坐标(依赖属性)
public double Y {
 get { return (double)GetValue(YProperty); }
 set { SetValue(YProperty, value); }
}
public static readonly DependencyProperty YProperty = DependencyProperty.Register(
 "Y",
 typeof(double),
 typeof(QXSpirit),
 new FrameworkPropertyMetadata(
 (double)0,
 FrameworkPropertyMetadataOptions.None,
 null,
 null
 )
);

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.