2013-07-24 117 views
1

所以,我想在我的光標前畫一個紋理。這裏是我的代碼:非靜態字段,方法或屬性'Microsoft.Xna.Framework.Input.MouseState.X.get'需要對象引用嗎?

private void DrawCursor() 
{ 
    //Draws cursor 
    Vector2 Mouseplace = new Vector2(MouseState.X, MouseState.Y); 
    spriteBatch.Draw(cursor, Mouseplace, Color.White); 
} 

而且我得到這個錯誤:

Error 1 An object reference is required for the non-static field, method, or property 'Microsoft.Xna.Framework.Input.MouseState.X.get' And this:

Error 2 An object reference is required for the non-static field, method, or property 'Microsoft.Xna.Framework.Input.MouseState.Y.get' How to fix those?

(很抱歉,如果這是一個noob問題)

回答

1

MouseState是不是一個靜態類..你需要要做到這一點:

var mouseState = Mouse.GetState(); 
Vector2 Mouseplace = new Vector2(mouseState.X, mouseState.Y); 

等X和Y分別爲MouseState中的公共屬性立場

0

看起來像MouseState根本不是static

您需要創建一個實例才能使用XY屬性..

相關問題