public static GameObject Instantiate(GameObjectFileData objData)
        {
            switch (objData.ObjectType)
            {
                case "SoulTrader.Player":
                    return new Player(null, objData.GraphicName, objData.Position, objData.Scale);
                case "SoulTrader.Obstacle":
                    return new Obstacle(objData.GraphicName, objData.Position, objData.Scale);
                case "SoulTrader.KillZone":
                    return new KillZone(objData.GraphicName, objData.Position, objData.Scale);
            }

            return new GameObject(objData.GraphicName, objData.Position, objData.Scale);
        }
示例#2
0
        private GameObject Instantiate(GameObjectFileData objData)
        {
            switch (objData.ObjectType)
            {
                case "SoulTrader.Player":
                    player = new Player(camera, objData.GraphicName, objData.Position, objData.Scale);
                    return player;
                case "SoulTrader.Obstacle":
                    return new Obstacle(objData.GraphicName, objData.Position, objData.Scale);
                case "SoulTrader.KillZone":
                    return new KillZone(objData.GraphicName, objData.Position, objData.Scale);
            }

            return new GameObject(objData.GraphicName, objData.Position, objData.Scale);
        }
示例#3
0
        public void Save(string destinationFilePath)
        {
            List<GameObjectFileData> objects = new List<GameObjectFileData>();
            foreach (GameObject obj in scene)
            {
                GameObjectFileData objectData = new GameObjectFileData();
                objectData.ObjectType = obj.GetType().ToString();
                objectData.GraphicName = obj.GraphicsObject.TextureString;
                objectData.Position = obj.BottomLeftPosition;
                objectData.Scale = obj.Scale;

                objects.Add(objectData);
            }

            XmlRootAttribute root = new XmlRootAttribute();
            root.ElementName = "object";
            root.IsNullable = true;

            FileStream stream = File.Open(destinationFilePath, FileMode.Create);

            XmlSerializer serializer = new XmlSerializer(typeof(List<GameObjectFileData>), root);
            serializer.Serialize(stream, objects);

            stream.Close();
        }