Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.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# 在XNA中找不到TitleContainer.OpenStream文件_C#_Xna_Streaming_Xna 4.0_Game Engine - Fatal编程技术网

C# 在XNA中找不到TitleContainer.OpenStream文件

C# 在XNA中找不到TitleContainer.OpenStream文件,c#,xna,streaming,xna-4.0,game-engine,C#,Xna,Streaming,Xna 4.0,Game Engine,我试图在运行时加载许多图像,并将每个图像分配给要显示的Texture2D对象usnig XNA,我使用TitleContainer.OpenStream(“Content/”+fileName+“.png”) 运行项目,我将面临此异常: Microsoft.Xna.Framework.dll中发生类型为“System.IO.FileNotFoundException”的未处理异常 其他信息:加载“Content\Background.png”时出错。找不到文件 尽管所有图像都是在内容中设置的 这

我试图在运行时加载许多图像,并将每个图像分配给要显示的Texture2D对象usnig XNA,我使用TitleContainer.OpenStream(“Content/”+fileName+“.png”) 运行项目,我将面临此异常:

Microsoft.Xna.Framework.dll中发生类型为“System.IO.FileNotFoundException”的未处理异常 其他信息:加载“Content\Background.png”时出错。找不到文件

尽管所有图像都是在内容中设置的

这是加载图像并创建Texture2D对象的方法的全部代码

专用静态纹理2D LoadTextureStream(图形设备图形,字符串位置) { Texture2D file=null; RenderTarget2D结果=空

        using (Stream titleStream = TitleContainer.OpenStream("Content/" + loc + ".png"))
        {
            file = Texture2D.FromStream(graphics, titleStream);
        }

        //Setup a render target to hold our final texture which will have premulitplied alpha values
        result = new RenderTarget2D(graphics, file.Width, file.Height);

        graphics.SetRenderTarget(result);
        graphics.Clear(Color.Black);

        //Multiply each color by the source alpha, and write in just the color values into the final texture
        if (blendColor == null)
        {
            blendColor = new BlendState();
            blendColor.ColorWriteChannels = ColorWriteChannels.Red | ColorWriteChannels.Green | ColorWriteChannels.Blue;

            blendColor.AlphaDestinationBlend = Blend.Zero;
            blendColor.ColorDestinationBlend = Blend.Zero;

            blendColor.AlphaSourceBlend = Blend.SourceAlpha;
            blendColor.ColorSourceBlend = Blend.SourceAlpha;
        }

        SpriteBatch spriteBatch = new SpriteBatch(graphics);
        spriteBatch.Begin(SpriteSortMode.Immediate, blendColor);
        spriteBatch.Draw(file, file.Bounds, Color.White);
        spriteBatch.End();

        //Now copy over the alpha values from the PNG source texture to the final one, without multiplying them
        if (blendAlpha == null)
        {
            blendAlpha = new BlendState();
            blendAlpha.ColorWriteChannels = ColorWriteChannels.Alpha;

            blendAlpha.AlphaDestinationBlend = Blend.Zero;
            blendAlpha.ColorDestinationBlend = Blend.Zero;

            blendAlpha.AlphaSourceBlend = Blend.One;
            blendAlpha.ColorSourceBlend = Blend.One;
        }

        spriteBatch.Begin(SpriteSortMode.Immediate, blendAlpha);
        spriteBatch.Draw(file, file.Bounds, Color.White);
        spriteBatch.End();

        //Release the GPU back to drawing to the screen
        graphics.SetRenderTarget(null);

        return result as Texture2D;
    }

任何帮助??(注意:iam在windows 7上使用XNA 4.0)

首先,查看您的bin文件夹,确保该文件在运行时确实存在。如果不存在,请右键单击有问题的内容项,并确保生成操作设置为“复制到输出目录”或“复制到更新的目录”

using (Stream titleStream = TitleContainer.OpenStream("Content/" + loc + ".png"))

尝试在不使用“.png”短语的情况下使用此选项,并选中“Content\\”-这两个选项中的任何一个都可以使用。

我可能错了,但我认为问题出在这里:

using (Stream titleStream = TitleContainer.OpenStream("Content/" + loc + ".png"))
尝试在不使用“.png”短语的情况下使用此选项,并选中“Content\\”-这两个选项中的任何一个都可以使用。

(Xbox360) 对我来说,解决方案是在“内容”部分加前缀

Stream soundfile=TitleContainer.OpenStream(@“Sound/explosion.wav”);//(Xbox360)
对我来说,解决方案是在“内容”部分加前缀

streamsoundfile=TitleContainer.OpenStream(@“Sound/explosion.wav”)//
   Stream soundfile = TitleContainer.OpenStream(@"Content/Sound/explosion.wav"); //<- Win
   boomEffect = SoundEffect.FromStream(soundfile);
   soundEffectInstance = boomEffect.CreateInstance();