在我MainPage嘗試運行函式(ShowEntity)時,影像不會顯示在背景上。當我在我的播放器(我的專案中的類)上運行它時,影像不會顯示在螢屏上。我試圖改變格式幾次,但我沒有發現問題。我認為 ShowEntity 函式有問題。
這是我如何嘗試使其作業的一個示例。
Player _player1 = new Player(500, 500, 150, 150, "ms-appx:///Asssets/Player5.gif");
public class Piece
{
private double _x;
private double _y;
public int _width;
private int _height;
public string _image;
public Image _imagesource { get; set; }
public Piece(double x, double y, int width, int height, string image)//BitmapImage imagesource)
{
_x = x;
_y = y;
_image = image;
_width = width;
_height = height;
_imagesource = ShowEntity();
}
private Image ShowEntity()
{
Image _img = new Image();
_img.Source = new BitmapImage(new Uri(_image));
_img.Height = _height;
_img.Width = _width;
Canvas.SetLeft(_img, _x);
Canvas.SetTop(_img, _y);
GameManager.MyCanvas.Children.Add(_img);
return _img;
}
uj5u.com熱心網友回復:
問題看起來你的影像被其他元素覆寫,如果你想在畫布中顯示元素,你需要為元素設定ZIndex。
Canvas.ZIndex 宣告 Canvas 的子元素的繪制順序。當子元素的任何邊界之間存在重疊時,這很重要。較高的 z 順序值將在較低的 z 順序值之上繪制。如果未設定值,則默認值為 -1。
如果要將影像設定為背景,則可以將其設定為 ZIndex 并使用 samll 值。而另一種方式是直接用ImageBrush設定Canvas Background,就像流動一樣。
MyCanvas.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri(this.BaseUri, "ms-appx:///Assets/enemy.png")), Stretch = Stretch.Fill };
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/485883.html
