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

Source: Internet
Author: User
Tags silverlight

C # development Wpf/silverlight animation and games series (Game Course): (19) The slick of the Perfect Elf (WPF only) ③

First of all, I would like to develop a series of wpf/silverlight animation and game Tutorials (Game Course) in C #: (18) the Last ② () method of the slick (WPF only) Changeaction of the perfect wizard makes some additional explanations. One of the effects of this method is to set the start and end frames of the wizard's slice animation based on the current action of the wizard:

As pictured above, we can clearly see the currentstartframe and Currentendframe of the Elves ' 5 actions respectively. These two parameters are important because in the wizard's lifeline we can implement a Dynamic Update wizard role picture with the following yellow area code to form a continuous animation:

//精灵线程间隔事件
private void Timer_Tick(object sender, EventArgs e) {
……
//动态更改精灵图片源以形成精灵连续动作
Body.Source = Source[(int)Direction, FrameCounter];
FrameCounter = FrameCounter == CurrentEndFrame ? CurrentStartFrame : FrameCounter + 1;
}

For example: When the Elves are running, the Framecounter starts at 5 and then advances with a 1 unit ladder, the target is 12, and then returns 5 after 12 to repeat the previous process; When the genie is casting, the framecounter starts counting from 20, Then take 1 as the unit ladder to advance, the target is 25, when to 25 and then return 20 repeat the previous process. The others, etc...

After enriching the principle of sprite animation, we go back to the topic of this section: How to make the sprite display the correct orientation and precise positioning and stopping when moving.

Do you remember the point where I ended up in the sixth section with a little mention of the relevant implementation, but did not implement it, but also a small reflection for everyone. But in this section, since I have the title of the Perfect Genie, I am not going to disappoint all my friends ' expectations, we first analyze the steps to implement the 8 Direction Wizard:

1. Get the current coordinates of the protagonist, which has been perfectly implemented in the 15th section, and is also positioned to the bottom of the foot (SPIRIT.X,SPIRIT.Y).

2, get the target coordinates, that is, the left mouse button (or right) click on the coordinates of the point, the coordinates we can use the left mouse button (or right button) Click on the event easy to get, which in the previous chapters have a lot of mention.

3, take the above two coordinates as the parameter, calculates the protagonist's current orientation and returns a numerical code number (0-7 corresponds 8 direction respectively) by the tangent value calculation formula.

How to do this, and look at the following figure:

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.