Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 不';t内容加载<;纹理2d>;()是否创建新实例?_C#_Reference_Xna_Xna 4.0 - Fatal编程技术网

C# 不';t内容加载<;纹理2d>;()是否创建新实例?

C# 不';t内容加载<;纹理2d>;()是否创建新实例?,c#,reference,xna,xna-4.0,C#,Reference,Xna,Xna 4.0,我有这个结构: public struct LevelElements { public Texture2D levelTexture; // other variables... } 我用这种方式初始化它: for (int i = 0; i < 2; i++) levelElements[i] = new LevelElements { levelTexture = content.Load<Texture2D>("Terr

我有这个结构:

public struct LevelElements
{
    public Texture2D levelTexture;
    // other variables...
}
我用这种方式初始化它:

for (int i = 0; i < 2; i++)
    levelElements[i] = new LevelElements
    {
        levelTexture = content.Load<Texture2D>("Terrain/level"),
        // other variables...
    }
for(int i=0;i<2;i++)
levelElements[i]=新的levelElements
{
levelTexture=content.Load(“地形/标高”),
//其他变量。。。
}
然后我绘制第一个纹理,同时使用
textureLevel.SetData
方法修改它。
问题是,如果我绘制第二个,它看起来与修改后的第一个相同,而不是从内容加载的原始版本。
为什么两个
levelTexture
s的引用相同?
Content.Load()
是否创建新实例


PS:我不需要创建该纹理的副本,我只是在测试我的代码,我发现了这种行为。

我以前没有使用过它,但在我看来,您可能希望这样声明它,以便将其用作实例变量:

Texture2D纹理=新纹理2d(
资源设备,
image.PixelWidth,
image.PixelHeight,
假,,
表面形态(颜色)


:来自msdn

Nice方法,但BitmapSourceExtensions.CopyTo似乎只存在于Silverlight中。不管怎样,您的解决方案是正确的,“强制”创建一个新实例,现在就可以了!是的,我不是建议你使用那个确切的方法,只是你需要实例化一个Texture2D的“新”实例,而不是使用静态声明。这正是我想要的。