【问题标题】:How should I pass a Texture2D as a parameter?我应该如何将 Texture2D 作为参数传递?
【发布时间】:2016-01-09 01:13:48
【问题描述】:

我正在用 C# 和 XNA 制作游戏,我想在类构造函数中使用 Texture2D 作为参数。我应该使用以下哪种方法?

1.

//Load the texture as a variable and then pass it
Texture2D myTexture = Content.Load<Texture2D>("MyTexture");
MyClass myClass = new MyClass(myTexture);

2.

//Pass the loading code without storing it in a variable
MyClass myClass = new MyClass(Content.Load<Texture2D>("MyTexture"));

如果使用另一种方法就不会出现使用一种方法的后果吗?如果是这样,首选哪种方法?或者我使用哪种方法无关紧要?

【问题讨论】:

    标签: c# parameters xna arguments texture2d


    【解决方案1】:

    如果您在将资产传递给容器之前碰巧不必对资产做任何事情,那真的没有区别。我更喜欢方法 1。虽然为了更好的可读性。

    【讨论】:

      猜你喜欢
      • 2021-08-26
      • 2022-01-13
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 2021-04-13
      • 1970-01-01
      • 2015-10-02
      • 1970-01-01
      相关资源
      最近更新 更多