0
好吧,所以我試圖運行我的xna遊戲,並且繼續在我的敵人類的繪製方法中爲以下代碼彈出空引用異常,但我已不知道是什麼導致它。對象引用未設置爲對象的實例XNA
特別是我所指的代碼是
drawing Origin = new Vector2(texture.Width/2, texture.Height/2);
。
public void Draw(SpriteBatch spriteBatch)
{
boundingBox.X = (int)position.X;
boundingBox.Y = (int)position.Y;
drawingOrigin = new Vector2(texture.Width/2, texture.Height/2);
spriteBatch.Draw(texture, boundingBox, null, Color.White, orientation, drawingOrigin, SpriteEffects.None, 0.0f);
}
是紋理當你設置一個斷點並調試它時爲null? – Jonesopolis
'對象引用'錯誤總是一樣的。您正試圖對其值爲null的對象調用屬性。 「紋理」是物體,「寬度」是屬性。 'null'沒有一個名爲'Width'的屬性,所以會拋出一個錯誤。 – paqogomez
Jonesy yes drawingOrigin行在斷點處顯示紋理爲null。 –