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

Source: Internet
Author: User
Tags silverlight

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

In the previous section, we achieved a map traction movement, while still leaving behind a small tail: how can the protagonist and the obstacle move along with the map movement?

A bit to the last section, as long as the map moving at the same time, always according to the protagonist and other objects of the x,y coordinates relative to the map of the x,y coordinate movement to achieve the goal. But this leads to a new problem: the protagonist is the image control, the obstacles are rectangular control, they do not x,y these two properties, how do we record their coordinates?

The simplest and most straightforward way to do this is to connect their x,y coordinates to the tag property by using a delimiter and then detach it from the call. For example, we can do this when building obstacles:

`//构建障碍物(本节只为演示，随便建一个) for (int y = 11; y <= 14; y++) { 　for (int x = 31; x <= 40; x++) { 　　//障碍物在矩阵中用0表示 　　Matrix[x, y] = 0; 　　rect = new Rectangle(); 　　//目前暂时不新创一个自定义控件，而把坐标储存在Tag属性中 　　rect.Tag = x + "," + y; 　　…… 　} }`

The yellow code in the image above is to record the x,y coordinates of the obstructions into its Tag property, and then we can detach the tag property by using the following function when needed:

`//从矩形障碍物的Tag属性中分离出它的坐标Point private Point getPointFromTag(object tag) { 　string[] str = tag.ToString().Split(new char[] { ',' }); 　return new Point(Convert.ToDouble(str[0]), Convert.ToDouble(str[1])); }`

However, the efficiency of doing so is extremely low, and, more important, it has no expansion to speak of. The obstacle is good to deal with, if is the protagonist? It not only has the X,y two attributes, also has the name, the Mempai, the blood bar, the blue stripe, the Jin Mu Fire and Fire Earth, the strength, the wisdom ..., the thread parameter, the direction, the equipment code number and so on and so on (faint ...) Too many, too many of the various attributes, difficult to all to record into this tag property? It's a terrible thing to put Tyrannosaurus rex in a cage, and it's hard to take, too! Two words: Horror.

Reader's voice: boss, what should I do? Can't you even hang yourself?

Author: Ann, What's the hurry? Here's the point. You have to look seriously, super BIG one essence!!!

If there are friends who have done game development, or have learned about game development related content friends will find that the game in addition to the map engine, the most crucial thing is the creation of the wizard. Elves are the most common objects in the game, it can be the protagonist, can be other players, can be NPC, can be monsters and boss, can even be mounts, obstacles and so on. Many novice friends are often worried about how to use foreign-made generic elves (after all, the intricacies of English jargon and the excessive object attributes and methods that most people cannot easily good grasp). Luckily, we can find powerful and simple related support in the Wpf/silverlight, which is the legendary Wizard control I'll explain in more detail below!

Let's start by looking at how to create a wizard control in Wpf/silverlight. The first step is to add a folder in the project (named controls) to classify and save it, then right click on the folder to add a user control (named Qxspirit.xaml, Hey, of course, other names are OK, happy on the good), the following figure.

Related Keywords:

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.