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

Source: Internet
Author: User
Tags silverlight

C # development Wpf/silverlight animation and game series Tutorials (Game Course): (25) perfect capture the elves of the artifact-hittest

Monsters have appeared, how to choose their favorite strange is the protagonist is the first thing to do.

To make a difference in the mouse state, I first constraint on the mouse change rule: When the mouse on the screen in the open map area to move, the mouse cursor pattern is displayed as the default cursor (No. 0 number cursor picture), when the Mouse through the wizard (hover over it) becomes a light-emitting cursor (number 1th cursor picture), If the Sprite object is hostile, the mouse cursor changes to the attack cursor (image 2nd), and when the Magic shortcut is used, the mouse cursor becomes the coagulation state (the 3rd cursor picture).

The next thing to do is to implement these rules in code. To implement the mouse cursor transformation, we first have to add these 4 cursors to the system, here I create a new folder named Cursors to save these 4 cursors, add the method detailed in section fifth. Then, when used, if the code cursor does not exist, the cursor is added to the system memory through the data flow:

public static Cursor[] GameCursors = new Cursor[4];

/// <summary>

/// 返回指定标号光标

/// </summary>

/// <param name="sign">标号</param>

/// <returns>光标</returns>

public static Cursor getCursor(int sign) {

 if (GameCursors[sign] == null) {

  GameCursors[sign] = new Cursor(new FileStream(string.Format(@"Cursors\{0}.ani", sign), FileMode.Open, FileAccess.Read, FileShare.Read));

 }

 return GameCursors[sign];

}

Everything is in place, and now it is time to implement the game form's Mouse movement events. Since it is the effect that the mouse slides on the map, we first add the game Form Mouse movement event: mousemove= "Window_mousemove", and then write the corresponding content in the Window_mousemove method in the background code:

private void Window_MouseMove(object sender, MouseEventArgs e) {

 this.Cursor = e.Source is QXSpirit ? Super.getCursor(1) : this.Cursor = Super.getCursor(0);

}

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.