我在哪里将自定义Levels文件夹放在XNA游戏中?

时间:2020-12-13 09:17:06

I am quite lost with where and how to store the *.txt level files in my game.

我很遗憾在哪里以及如何在我的游戏中存储* .txt级文件。

What I want in my game is the availability of a few "prebaked" levels that come installed with the game but also the ability for users to create their OWN levels.

我在游戏中想要的是游戏中安装的一些“预烘焙”级别的可用性,以及用户创建自己的OWN级别的能力。

So what I did is created a new directory inside visual studio in the "Content" called levels, and put a "level1.txt" there. But the only way I can access the level *.txt files is by using full path, and I cannot INCLUDE them in my visual studio solution because it does not build:

所以我所做的是在视觉工作室内创建一个名为levels的“内容”中的新目录,并在其中放置一个“level1.txt”。但我可以访问级别* .txt文件的唯一方法是使用完整路径,我不能在我的visual studio解决方案中包含它们,因为它不构建:

 "C:\My Documents\blahblabh....\levels\level1.txt"
  • Do I put these "prebaked" maps instead into some directory near the executable? How do I create a directory inside the /bin directory Before I compile the project?
  • 我是否将这些“预烘焙”地图放入可执行文件附近的某个目录中?如何在/ bin目录中创建目录在编译项目之前?

  • How do I dissalow users from deleting the "prebaked" levels that come installed with the game?
    (I no longer need this)
  • 如何禁止用户删除随游戏一起安装的“预烘焙”级别? (我不再需要这个)

  • Also, Where do I store the User Custom created levels? I assume that should be done with StorageDevice. But that ties in with the first question on how to create a directory after game is deployed.
  • 此外,我在哪里存储用户自定义创建的级别?我认为应该使用StorageDevice完成。但这与第一个问题有关,即在部署游戏后如何创建目录。

Any pointers would be welcome! Thank you

任何指针都会受到欢迎!谢谢

EDIT: Re: custom content processor. This seems way more complicated then I need. But I need to deploy my game to xbox360 as well, so will the Storage Device work?

编辑:Re:自定义内容处理器。这似乎比我需要的更复杂。但是我需要将我的游戏部署到xbox360,存储设备也可以工作吗?

2 个解决方案

#1


You could write an custom content processor to handle your level files, but it is probably overkill. This has the advantage that you can "compile" the levels to some format that would be more difficult for a user to modify.

您可以编写一个自定义内容处理器来处理您的级别文件,但它可能有点过分。这样做的好处是,您可以将级别“编译”为某种格式,这对用户来说更难以修改。

You can just add it to your project (not in Content) and specify "Copy to Output Directory - Copy always" in properties. Create a new subfolder in your project and place it there - that'll be the directory it is copied to.

您只需将其添加到项目中(而不是在内容中),并在属性中指定“复制到输出目录 - 始终复制”。在项目中创建一个新的子文件夹并将其放在那里 - 这将是它被复制到的目录。

For disallowing users deleting prebaked levels, no way on Windows to allow for that. You could do a check in your code that would cause it to fail if a user were to delete some expected files.

禁止用户删除预烘焙级别,Windows上无法允许这样做。您可以检查代码,如果用户要删除某些预期的文件,则会导致代码失败。

For creating a new directory, you can use the StorageDevice.OpenContainer().Path to get the root path and use Directory.CreateDirectory. This'll work on PC and XBox.

要创建新目录,可以使用StorageDevice.OpenContainer()。Path获取根路径并使用Directory.CreateDirectory。这将适用于PC和XBox。

#2


You should definitely put "prebaked" levels with the executable. I don't use VS, so I can't tell you how to do that.

你绝对应该在可执行文件中添加“预烘焙”级别。我不使用VS,所以我不能告诉你如何做到这一点。

There really is no way to prevent users from deleting your levels, but you could use a hash to verify that they haven't been modified (users can still get around this by modifying your executable, but that should stop most users).

实际上没有办法阻止用户删除你的级别,但你可以使用哈希来验证它们是否未被修改(用户仍然可以通过修改你的可执行文件来解决这个问题,但这应该会阻止大多数用户)。

You should put custom levels in the user's folder, like C:\Documents and Settings\User\MyGame\levels\level.txt.

您应该将自定义级别放在用户的文件夹中,例如C:\ Documents and Settings \ User \ MyGame \ levels \ level.txt。

#1


You could write an custom content processor to handle your level files, but it is probably overkill. This has the advantage that you can "compile" the levels to some format that would be more difficult for a user to modify.

您可以编写一个自定义内容处理器来处理您的级别文件,但它可能有点过分。这样做的好处是,您可以将级别“编译”为某种格式,这对用户来说更难以修改。

You can just add it to your project (not in Content) and specify "Copy to Output Directory - Copy always" in properties. Create a new subfolder in your project and place it there - that'll be the directory it is copied to.

您只需将其添加到项目中(而不是在内容中),并在属性中指定“复制到输出目录 - 始终复制”。在项目中创建一个新的子文件夹并将其放在那里 - 这将是它被复制到的目录。

For disallowing users deleting prebaked levels, no way on Windows to allow for that. You could do a check in your code that would cause it to fail if a user were to delete some expected files.

禁止用户删除预烘焙级别,Windows上无法允许这样做。您可以检查代码,如果用户要删除某些预期的文件,则会导致代码失败。

For creating a new directory, you can use the StorageDevice.OpenContainer().Path to get the root path and use Directory.CreateDirectory. This'll work on PC and XBox.

要创建新目录,可以使用StorageDevice.OpenContainer()。Path获取根路径并使用Directory.CreateDirectory。这将适用于PC和XBox。

#2


You should definitely put "prebaked" levels with the executable. I don't use VS, so I can't tell you how to do that.

你绝对应该在可执行文件中添加“预烘焙”级别。我不使用VS,所以我不能告诉你如何做到这一点。

There really is no way to prevent users from deleting your levels, but you could use a hash to verify that they haven't been modified (users can still get around this by modifying your executable, but that should stop most users).

实际上没有办法阻止用户删除你的级别,但你可以使用哈希来验证它们是否未被修改(用户仍然可以通过修改你的可执行文件来解决这个问题,但这应该会阻止大多数用户)。

You should put custom levels in the user's folder, like C:\Documents and Settings\User\MyGame\levels\level.txt.

您应该将自定义级别放在用户的文件夹中,例如C:\ Documents and Settings \ User \ MyGame \ levels \ level.txt。