xna 4.0 和加载图像失败 [英] xna 4.0 and loading images fails

查看:32
本文介绍了xna 4.0 和加载图像失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 png 图像加载到我的游戏中,但由于某种原因它找不到图像.

I'm trying to load png images into my game, but for some reason it can't find the images.

这是我正在尝试加载图像的标题屏幕:

This is my Title screen that is trying to load the images:

public TitleScreen(ContentManager contentManager)
  {
     titleScreen = contentManager.Load<Texture2D>("gfx\\titleScreen");
     bgScreen = contentManager.Load<Texture2D>("gfx\\bgScreen");
     arialFont = contentManager.Load<SpriteFont>("Arial");
  }

这里我设置了内容的根目录:

Here I'm setting the root directory for the content:

Content.RootDirectory = "Content";

当我的程序点击标题屏幕时,它找不到图像,但是它的路径是正确的,图像也被设置为内容并复制到输出目录.

When my program hits titlescreen, it fails to find the image, however the path to it is correct and the images are also set to be Content and copied to output directory.

当我尝试调试它时,它告诉我它找不到图像Content\gfx\titleScreen.xnb".出于某种原因,它正在尝试加载一个 xnb 文件,有没有我可以更改它的地方,或者我需要做任何其他事情吗?

When I try to debug it, it tells me it can't find image "Content\gfx\titleScreen.xnb". For some reason it is trying to load an xnb file, is there anywhere that I can change it, or do I need to do anything else?

推荐答案

在 XNA 中,图像被编译为 .xnb 文件,而不是 .png 或 .jpg

In XNA Images are compiled .xnb files and not .png or .jpg

XNA 3.0 ||XNA 3.1
您将内容添加到项目中的内容文件夹

XNA 3.0 || XNA 3.1
You add your Content to the Content folder within your project

XNA 4.0
您有一个内容项目,并在当前项目中添加了一个内容引用

XNA 4.0
You have a Content Project and you add a Content Reference in your current project

还要确保设置图像的属性:右键单击内容项 -> 属性 -> 设置以下内容

Also Make sure you set the properties of the images: Right Click on Content Item -> Properties -> Set the following

  • 构建操作:编译
  • 内容导入器/处理器:纹理 - XNA 框架(纹理)
  • 内容导入器/处理器:Sprite 字体描述 - XNA 框架(字体)
  • 请勿复制

这篇关于xna 4.0 和加载图像失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆