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);
}