Game Development Community

Loading Particle Effect from XML

by James Kennedy · in Torque X 2D · 07/25/2007 (4:15 pm) · 4 replies

Is there any way to load emitter data from the .eff xml file within C#, or does it have to be done in TXB?

#1
07/27/2007 (7:19 am)
Yep, just use the same sceneloader method you use to load txscenes.

You might run into some errors if you havent loaded the materials (they are all saved in the txscene files) the effect uses before you try and load it.

You can get round that by putting the material definition in the eff file, but you have to do it manually.
#2
07/27/2007 (11:40 am)
Thanks, I'll try that out.
#3
07/27/2007 (3:00 pm)
I'm having some difficulty loading my particles with the scene loader, heres what I have:

SceneLoader sl = Game.Instance.SceneLoader;

sl.OnSceneUnloaded = Game.Instance.OnSceneUnloaded;
sl.UnloadLastScene();

// load templates
sl.OnSceneLoaded = null;
sl.Load(@"data\levels\templates.txscene");

// load particles
sl.Load(@"data\particles\myeffect.eff");

// load the level
sl.OnSceneLoaded = Game.Instance.OnSceneLoaded;
sl.Load(@"data\levels\test2.txscene");

Then later when I want to use the particle i have:

T2DParticleEffect peffect = (T2DParticleEffect)TorqueObjectDatabase.Instance.FindObject("myeffect");
if (peffect != null)
{
peffect.Position = projectile.Position;
TorqueObjectDatabase.Instance.Register(peffect);
}

The problem is, its not finding my particle effect in the object database. It is clearly given a name in the XML file, so I'm not sure why its not finding it. Ideas?
#4
07/28/2007 (6:38 pm)
Well, you don't need to register it, as it is already registered when you load the .eff file.

I am using something like this:
public T2DParticleEffect TurretEffect
{
get
{
if (_turretEffect == null)
{
Game.Instance.SceneLoader.Load(@"data\effects\TurretAuraV2.eff");
_turretEffect = TorqueObjectDatabase.Instance.FindObject("TurretAura");
}
return _turretEffect;
}
set { _turretEffect = value; }
}