在 Visual Studio 的解决方案资源管理器中组织项目文件

发布于 2024-12-02 09:25:59 字数 429 浏览 1 评论 0原文

我正在制作我的第一个 D3D 简单游戏。我的游戏使用了很多图像。

这是我在磁盘上的组织:

MyGame
|
|-Debug
|-Release
|-Assets
  |-Others
  |-Images
|All cpp and h fiels here

如果我从 Visual Studio 启动游戏,则该游戏正在运行。但是,如果我从 Windows 启动游戏(通过单击 Release 文件夹中的 EXE 文件),我会收到一条错误消息,指出我的应用程序无法加载图像。这是因为在我的应用程序中,我引用了“Assets\Images\image.bmp”等图像。

我应该如何组织我的项目?

现在,我必须在 Release 文件夹和主项目文件夹中复制 Assets 文件夹。

I'm making my first D3D simple game. My game uses many images.

This is my organization on disk:

MyGame
|
|-Debug
|-Release
|-Assets
  |-Others
  |-Images
|All cpp and h fiels here

If I launch my game from Visual Studio, thr game is working. But if I launch the game from Windows (by clicking the EXE file in the Release folder), I get an error that my application can't load images. This is because in my app I refer to those images like "Assets\Images\image.bmp".

How should I organize my project?

Now I have to make copy of the Assets folder in the Release folder and in the main project folder.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅一夜美梦 2024-12-09 09:25:59

我认为你的项目组织得很好;我的建议是不要依赖于特定的目录结构,只需要一个 app.config 或其他 XML .config 文件设置,或者一个注册表设置(但不要这样做)或一个环境变量(MY_GAME_ASSETS= "C:\path\to\assets"),或者甚至是命令行参数 (MyGame.exe --assets-dir="c:\path\to\assets\") 您可以在启动时设置 游戏;然后你可以将其指向正确的目录,无论它在哪里。

I think your project is organized fine; my suggestion would be instead of relying on a certain directory structure, just have an app.config or other XML .config file setting, or perhaps a registry setting (but don't do that) or an environment variable (MY_GAME_ASSETS="C:\path\to\assets"), or perhaps even a command line parameter (MyGame.exe --assets-dir="c:\path\to\assets\") that you can set on launching your game; then you can point that at the right directory wherever it is.

郁金香雨 2024-12-09 09:25:59

@shelleybutterfly 的答案的另一种可能性是始终相对地引用图像,例如“..\Assets\Images\abcde.bmp”。然后,当您部署时,只要相对关系仍然相同,您就可以将可执行文件放入相同类型的结构中。

例如项目:

MyGame
|-Debug
|-Release
|-Assets
  |-Others
  |-Images

例如部署:

C:\Program Files\MyGame
|-Bin (contains *.exe)
|-Assets
  |-Others
  |-Images

Another possibility to @shelleybutterfly's answer is to always refer to images relatively, e.g. as "..\Assets\Images\abcde.bmp". Then when you deploy you could put your executable in the same kind of structure as long as the relative relationship is still the same.

e.g. Project:

MyGame
|-Debug
|-Release
|-Assets
  |-Others
  |-Images

e.g. Deployment:

C:\Program Files\MyGame
|-Bin (contains *.exe)
|-Assets
  |-Others
  |-Images
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文