简体   繁体   中英

How to Create/Upload/Update XML files to add different levels for the game

I'm trying to Edit/Update the current XML files that I have, to edit the level slighlty, but when editing them in notepad++/updating them in Content nothing happens.

I am using XML level editing for the first time, the first 2 levels I managed to find online, but I would like to edit them/add my own ones.

Should I change something in the code, or update them differently?

This is the code that Loads the Level in Game1 class

This is the Level class

This is the code that I have in the current Level1, the values represent different objects

I have tried to edit the XML file in notepad++, and inside the VS, but not sure if I am doing anything wrong. As I have mentioned, I am a begginer and this is the first time I'm doing this, that's why I am here.

Thank you for your help in advance.

If you need any additional code, I will upload is ASAP.

As I said, what I am trying to achieve is to edit the current file, so for example instead of having 2x 5 array layouts, I will have 1 layout of 5's and 1 layout of 1's

<Level>
  <layout>
    <ArrayOfInt>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
    </ArrayOfInt>
    <ArrayOfInt>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>
      <int>5</int>

Look up C# serialization. This is a great starting point. What actually happens there is split into multiple "tasks", each responsible for different things:

  1. The Xml* classes (such as XmlSerializer )

These are responsible for serialization and deserialization top-level. Under the hood they also parse, validate, interpret (and much more) the XML file. This is the step that is the bridge between the "text" file (that's what an XML basically is, if you ignore the syntax and its "functions") and the programming language (in our case C#).

  1. the XML

This is straightforward. It's just the serialized representation of objects in your case. A whole bunch of data that will later on turn to objects.

  1. C# Attributes (such as XmlElement , XmlArray or XmlAttribute )

This is the magic that "binds" whatever XML data type or structure it finds to something that can be represented as an object.

The code you would write is how your workflow would interpret the XML. What seems to be missing from your code are the Xml* attributes over the structures/classes. See the MS Learn article and start from there.

For the record, XML is too verbose and error prone for simple levels. A binary file with a byte per square...

Most likely you have added or removed a line causing the array to mis-populate. Make sure to count the lines to match the original level's line count, or accidentally changed an open or close tag.


The other possibility is the content build is stale.

You have not stated CLI or VS so I will give both.

CLI:

dotnet clean

Then build as usual.

VS:

Select the Build menu and choose rebuild.


The true error message should present itself at this point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM