C # development Wpf/silverlight animation and games series Tutorials (Game Tutorial): (40)

Source: Internet
Author: User
Tags visibility silverlight

C # development Wpf/silverlight animation and games series (Game Tutorial): (40) to Silverlight transplant ②

Third, new features:

1 Add the game music and sound objects:

public static MediaElement gameMusic, gameAudio;

2 Add game mouse cursor:

//设置游戏鼠标光标
GameCursor.Stretch = Stretch.Fill;
GameCursor.Source = Super.GetImage("/Image/Cursor/0.png");

Updates the mouse cursor picture position in the mouse movement event, based on the hit test:

//鼠标移动(悬停)事件
private void Game_MouseMove(object sender, MouseEventArgs e) {
……
Point p = e.GetPosition(Root);
GameCursor.SetValue(Canvas.LeftProperty, p.X); GameCursor.SetValue(Canvas.TopProperty, p.Y);
……
}

This method realizes the mouse picture follows the cursor movement, but obviously affects the program overall performance (CPU consumption will increase obviously), if which friend can provide the better solution, looks the message to me.

3 Add click Water Droplets:

When the mouse left click on the screen, as long as it does not point to object objects, then display the cursor in the position of water droplets, and play its own animation. At present my Silverlight game engine uses only one cursor drop:

QXDecoration hitCursor;
/// <summary>
/// 加载光标点击水滴
/// </summary>
private void LoadHitCursor() {
 hitCursor = new QXDecoration() {
  Code = 1,
  EndFrame = 9,
  CenterX = 32,
  CenterY = 32,
 };
 hitCursor.Visibility = Visibility.Collapsed;
 Add(hitCursor);
}
//鼠标左键事件
private void Game_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
……
//出现光标水滴
hitCursor.Visibility = Visibility.Visible;
hitCursor.FrameCounter = 0;
hitCursor.Timer.Start();
hitCursor.Coordinate = p;
……
}

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.