【问题标题】:How to get the name of the content of a Texture2D xna如何获取 Texture2D xna 内容的名称
【发布时间】:2017-02-14 08:14:33
【问题描述】:

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

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

我需要稍后告诉我纹理 2d 内容的名称是“重复”的东西 谢谢!

【问题讨论】:

    标签: c# xna filenames texture2d


    【解决方案1】:

    你所问的答案是:

    repeat.Name.ToString();
    

    但这样做实际上是零意义的。您已经将 Texture2D 命名为“重复”?

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

     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();
    }
    

    类似的东西。

    【讨论】:

    • 如果我有一个数组呢?如何识别该项目的内容?
    • 与其他数组一样,类似这样: for (int i = 0; i
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-10
    • 2011-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    相关资源
    最近更新 更多