如何获取Texture2D xna的内容名称

How to get the name of the content of a Texture2D xna

我正在用 xna 开发游戏,我需要获取 texture2d 内容的名称,以了解按下的那个是否是正确的,因为它们会随机收费 例如

      repeat= Content.Load<Texture2D>("repeat");

我需要一些东西,稍后告诉我纹理 2d 的内容名称是 "repeat" 谢谢!

您所问的答案是:

repeat.Name.ToString();

但这样做实际上是零意义。您已经将 Texture2D 命名为 'repeat'?

如果您随机更改图像,则加载所有纹理,然后只绘制随机选择的纹理:

 repeat = Content.Load<Texture2D>("repeat");
 repeat1 = Content.Load<Texture2D>("repeat1");
 repeat2 = Content.Load<Texture2D>("repeat2");

public override void Draw(GameTime gameTime)
{
SpriteBatch.Begin();
if (random == 0)
{
SpriteBatch.Draw(repeat, Position, Color);
}
else if (random == 1)
{
SpriteBatch.Draw(repeat1, Position, Color);
}
else if (random == 2)
{
SpriteBatch.Draw(repeat2, Position, Color);
}
SpriteBatch.End();
}

类似的东西。