2
votes

I'm making a small XNA game, and to change maps I have "portals", I've stored the information about these portals in a XML file.

<?xml version="1.0" encoding="utf-8"?>
<XnaContent>
    <Asset Type ="Vars.Portals[]">
        <Item>
            <Position>319</Position>
            <Destination>Map002</Destination>
        </Item>
        <Item>
            <Position>139</Position>
            <Destination>Map001</Destination>
        </Item>
        <Item>
            <Position>319</Position>
            <Destination>Map001</Destination>
        </Item>
    </Asset>
</XnaContent>

in the Game1.cs file I've Declared "portal" as a variable

Portals[] portal;

and then in the loadContent area loaded the XML file into portal.

portal = Content.Load<Portals[]>("Portals/Test");

Unfortunately this is where my problem occurs, since when I try to use

portal[].position

with any number in the []'s I am given the same value, which is the last value in my list. I've looked at all the values while running it in visual basics and they all seem to be the same. Is there something obvious I'm missing here. I'm new with using XML. The data is held within my Vars namespace.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vars
{
public class Portals
{
    #region Position
    private static int StorePosition = 0;

    public int Position
    {
        get { return StorePosition; }
        set { StorePosition = value; }
    }
    #endregion
    #region Destination
    private static string StoreDestination = "";

    public string Destination
    {
        get { return StoreDestination; }
        set { StoreDestination = value; }
    }
    #endregion

    }
}
1

1 Answers

5
votes

Of course you're getting the same value; your properties are using static fields as their backing storage. Static members are shared across all instances of a class.