【发布时间】:2011-11-27 22:09:37
【问题描述】:
我正在尝试编写一些代码,以文本形式显示我的播放器的 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。
-
像这样?: spriteBatch = new Microsoft.Xna.Framework.Graphics.SpriteBatch(GraphicsDevice graphicsDevice);