我正在嘗試編寫一些代碼,用於在文本中顯示我的播放器的X值。 它告訴我,Microsoft.Xna.Framework.Graphics.SpriteBatch.DrawString
行需要一個對象引用。有任何想法嗎?這裏是我的代碼:我該如何解決「非靜態字段,方法或屬性需要對象引用...」
public void Effects(Player player)
{
string compassString = "";
int playerY = (int) (((player.position.X + player.width) * 2f)/16f);
if (playerY > 0)
{
compassString = "Distance: " + playerY + " feet left";
if (playerY == 1)
{
compassString = "Distance: " + playerY + " foot left";
}
}
else if (playerY < 0)
{
playerY *= -1;
compassString = "Distance: " + playerY + " feet right";
if (playerY == 1)
{
compassString = "Distance: " + playerY + " foot right";
}
}
else
{
compassString = "Distance: Level";
}
Color black;
black.R = (byte)((0xff + black.R)/2);
black.G = (byte)((0xff + black.R)/2);
black.B = (byte)((0xff + black.R)/2);
Microsoft.Xna.Framework.Graphics.SpriteBatch.DrawString(Main.fontMouseText, compassString, new Vector2((float) (0x16), (float) ((0x4a + (0x16)) + 0x30)), black, 0f, new Vector2(), (float) 1f, SpriteEffects.None, 0f);
}
您需要在SpriteBatch的實例上調用DrawString。 –
喜歡這個?:\t spriteBatch = new Microsoft.Xna.Framework.Graphics.SpriteBatch(GraphicsDevice graphicsDevice); –