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);
}
載入 800×600 地圖圖片,ZIndex=-1 作為背景層。
理想狀態:藍色區域為障礙物。
實際 GridSize=20 時:障礙物呈方塊近似,非完美貼合。
本節將綜合運用前八節知識,實現 2D 角色在地圖上移動與尋路。