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

Source: Internet
Author: User
Tags silverlight

C # development Wpf/silverlight animation and game series Tutorials (Game Course): (34) Map Editor was born!

So far, tutorial example in the game although the implementation of a *, but can not easily set obstacles for the map, and the game all maps are a large picture, the protagonist's move will lead to the form of the map of the non-stop cutting, the larger map brings negative performance loss more obvious. Slicing the map to achieve the maximum performance optimization: Load when loading on demand, map based on the location of the protagonist to show only a specific part of, and if you can also match any outline of the occlusion, then all this will be more perfect interpretation of our game. Development and production of map editor is imminent.

So in this section I will explain how to make a grid based on that Easy-to-use and powerful map editor, and first implement the obstacle setting function and a * search road simulation.

The first step: design layout

Universal editors must be able to adapt to all dimensions of the map, so I choose ScrollViewer as the hosting container for the map, and by setting its horizontalscrollbarvisibility and verticalscrollbarvisibility are auto so that it can adapt to the map size, that is, the local map exceeds the size of the form of the scroll bar appears. Since a scrollviewer can only host one content, so in order to be able to draw and erase obstacles on top of it, we must also add another transparent scrollviewer for carrying the barrier grid (GRID):

As the description says, these two scrollviewer must be consistent, that is, the size of the two, the position of the scroll bar at the same time the same performance:

//滚动窗体二级协动
private void ObstructionViewer_ScrollChanged(object sender, ScrollChangedEventArgs e) {
 ScrollViewer scrollViewer = sender as ScrollViewer;
 MapViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset);
 MapViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset);
}

The second step, the design function

1) Loading map:

OpenFileDialog to open a File selection dialog box, and the file selection filter filters to limit the type of loading pictures are *.jpg and *.png:

//载入地图
private void LoadMap_Click(object sender, RoutedEventArgs e) {
 OpenFileDialog loadMap = new OpenFileDialog() {
  CheckFileExists = true,
  CheckPathExists = true,
  Multiselect = false,
  Filter = "图像文件(*.jpg,*.png)|*.jpg;*.png",
 };
 loadMap.FileOk += new System.ComponentModel.CancelEventHandler(loadMap_FileOk);
 loadMap.ShowDialog();
}

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.