2014-04-18 348 views
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); 
    } 
+4

是紋理當你設置一個斷點並調試它時爲null? – Jonesopolis

+0

'對象引用'錯誤總是一樣的。您正試圖對其值爲null的對象調用屬性。 「紋理」是物體,「寬度」是屬性。 'null'沒有一個名爲'Width'的屬性,所以會拋出一個錯誤。 – paqogomez

+0

Jonesy yes drawingOrigin行在斷點處顯示紋理爲null。 –

回答

0

問題固定溶液在主的Game1邏輯在

Protected Override Content(ContentManager Content) 

我曾稱爲內容作爲

virtualAlien.Content(); 

,而不是把它作爲

virtualAlien.Content(Content); 
相關問題