Game Development Community

Working with templates and multiple Levels

by Arden · in Torque X 2D · 11/05/2010 (9:38 pm) · 6 replies

Hiya all, I'm curious to know if some of you have found a solution to working on multiple scenes with templates. Do you copy these templates to every scene? Or is there a way to serialize the process, where an XML is used to load the templates and another one is used for the scene?

I looked over the forums on this one, most notably this thread:
http://www.torquepowered.com/community/forums/viewthread/92187

That post seems to conclude that theres no real effective way to do it because you can only have one scene loaded in the editor. I'm wondering, a year later, if there have been any new ideas on how best to handle this or are we still stuck with copy pasting templates all over the place?

Thanks for any info!


#1
11/06/2010 (4:56 am)
What do you want to do, use spawners? If you want access to the "Spawners", because they just simply kick butt and you can see what you are doing.. the answer is no.

Unless... you use a modified version of the spawner in the PSK, which I've actually done, and yes, that does work pretty awesome. It works on an enum, instead of targeting a template in scene.. quite cool.

Theres other ways I'm sure... I just think most of them will revolve around using an enum, and rarely have anything to do with XML serialization.
#2
11/06/2010 (7:26 am)
Yeah, I want to use Spawners, but there's also some cloning and linking from templates done directly in code. Any chance you might want to share some of your code? I think I understand what an enum is supposed to do, but I never actually used one.

Thanks for your response btw
#3
11/06/2010 (6:07 pm)
I'll take a look at what "I" did, but it might be shaky at best. Your best bet would be to try and implement it on your own.. But I'll take a look, and if its worth sharing, I'll repost it here later.
#4
11/06/2010 (6:11 pm)
Well.. here you go, for all it's worth, in all its glory... Its actually alot better then i remembered it being, this may have been through a few revisions.

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

using Microsoft.Xna.Framework;

using GarageGames.Torque.Core;
using GarageGames.Torque.Sim;
using GarageGames.Torque.T2D;
using GarageGames.Torque.XNA;

using GarageGames.Torque.PlatformerFramework;
using ProjectGert.Globals;

namespace ProjectGert.Spawners
{
    /// <summary>
    /// A spawn point that will automatically spawn it's object(s) when two scene objects are within a certain range.
    /// </summary>
    [TorqueXmlSchemaType]
    public class PreloadedTemplateProximitySpawner : ProximitySpawnPointComponent, ITickObject, IPauseable
    {

        public Globals.SpawnObjects.SpawnableTemplate SpawnTemplate
        {
            get { return _spawnTemplate; }
            set { _spawnTemplate = value; }
        }

        public override void CopyTo(TorqueComponent obj)
        {
            base.CopyTo(obj);

            PreloadedTemplateProximitySpawner obj2 = obj as PreloadedTemplateProximitySpawner;

            obj2.SpawnTemplate = SpawnTemplate;
        }


        protected override bool _OnRegister(TorqueObject owner)
        {
            if (!base._OnRegister(owner))
                return false;

            _spawnObject = TorqueObjectDatabase.Instance.FindObject(_spawnTemplate.ToString()) as T2DSceneObject;

            return true;
        }
 
        private Globals.SpawnObjects.SpawnableTemplate _spawnTemplate;
    }
}

The impotant thing to to note is that Globals.SpawnObjects.SpawnTemplate is an enum, that is placed in another class. The "Enum" should be an exact replication of the spawntemplates name, or it won't work obviously :)
#5
11/08/2010 (3:26 am)
If you're simply spawning objects in code with the .Clone(), you can load up a templates.txscene that contains all of your templates and then load your level scene on top of that. From there, just don't unload templates.txscene.

That way all of your templates are loaded whenever you need them.

If you want to use the templates in TXB then Will's idea is what I would do.
#6
11/10/2010 (3:56 pm)
@ Thanks for the code Will, it will come in very handy.

Thanks as well Cosmic, I got the answers I need.

It's great to get help along the way, really makes a difference.