C # development Wpf/silverlight animation and games series (Game Course): (ix) 2D game role on the map movement
This section will use the knowledge of the first two sections to the actual 2D game characters moving on the map, but also for the content of the front eight a comprehensive use of it.
Then start at the bottom of the map. First I add a map to the game window, where I also use the image control:
Image Map = new Image();
private void InitMap() {
Map.Width = 800;
Map.Height = 600;
Map.Source = new BitmapImage((new Uri(@"Map\Map.jpg", UriKind.Relative)));
Carrier.Children.Add(Map);
Map.SetValue(Canvas.ZIndexProperty, -1);
}
I add a map picture of a 800*600 named Map.jpg to the Project Map folder, and then set its Canvas.ZIndex property to-1 so that it acts as a map background. With this map, we need to set the barrier to it:
As can be seen from the above picture, the ideal state, the obstacle for me to fill in the blue area, which is ideal for the setting of obstacles. But in practice, take this tutorial, because the gridsize is set to 20, then the obstacles we end up with will be this: