简体   繁体   English

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

[英]Organizing project files in Solution Explorer in Visual Studio

I'm making my first D3D simple game. 我正在制作我的第一款D3D简单游戏。 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. 如果我从Visual Studio启动游戏,则游戏正在运行。 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. 但是如果我从Windows启动游戏(通过单击Release文件夹中的EXE文件),我会收到一个错误,我的应用程序无法加载图像。 This is because in my app I refer to those images like "Assets\\Images\\image.bmp". 这是因为在我的应用中我指的是像“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. 现在我必须在Release文件夹和主项目文件夹中复制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; 我的建议是,而不是依赖于某个目录结构,只需要app.config或其他XML .config文件设置,或者可能是注册表设置(但不要这样做)或环境变量( MY_GAME_ASSETS="C:\\path\\to\\assets" ),或者甚至可以在启动游戏时设置的命令行参数( MyGame.exe --assets-dir="c:\\path\\to\\assets\\" ); then you can point that at the right directory wherever it is. 然后你可以指向正确的目录,无论它在哪里。

Another possibility to @shelleybutterfly's answer is to always refer to images relatively, eg as "..\\Assets\\Images\\abcde.bmp". @ shelleybutterfly的答案的另一种可能性是总是相对地引用图像,例如“.. \\ 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. 然后在部署时,只要相对关系仍然相同,就可以将可执行文件放在相同类型的结构中。

eg Project: 例如项目:

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

eg Deployment: 例如部署:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Visual C ++项目中组织文件 - Organizing files in Visual C++ project 如何运行 Visual Studio 解决方案而无需在解决方案资源管理器中添加包含的文件显示? - How to run a Visual Studio solution without having to add the included files show in the Solution Explorer? 如何从Visual Studio中的项目解决方案中删除其他构建文件 - How to Delete Additional build files from the Project Solution in visual studio 在Visual Studio(2005)下使用Makefile而不是Solution / Project文件 - Using Makefile instead of Solution/Project files under Visual Studio (2005) Microsoft Visual Studio(2008) - 在解决方案资源管理器中过滤 - Microsoft Visual Studio (2008) - Filters in the Solution Explorer 我无法在解决方案资源管理器Visual Studio Community 2015中运行多个文件 - I cannot run multiple files within solution explorer Visual Studio Community 2015 Visual Studio,在某个过滤器(位于解决方案资源管理器中)内的所有文件中查找/替换文本 - Visual Studio, find/replace text within all files inside a certain Filter (of Solution Explorer) visual studio项目文件 - visual studio project files 将CMake项目添加到Visual Studio解决方案 - Adding a CMake project to a Visual Studio solution Visual Studio 不保存启动项目和解决方案配置 - Visual Studio not saving startup project and solution config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM