Layer control of particles
by Luke D · in Torque Game Builder · 07/24/2005 (5:00 pm) · 5 replies
Haven't seen this mentioned before (perhaps it isn't considered a bug) but a fxParticleEffect2D won't properly emit particles to a specific layer unless the .setLayer() function is called *after* playEffect. If you set it like so:
It just emits to layer zero. If you move the .setLayer() call to after the playEffect() call, it works properly.
%emitter = new fxParticleEffect2D() {scenegraph = t2dSceneGraph;};
%emitter.setLayer(15);
%emitter.playEffect();It just emits to layer zero. If you move the .setLayer() call to after the playEffect() call, it works properly.
About the author
#2
I was doing:
And they were all appearing on layer zero. If I echo($emitter.getLayer()) at this point I see that the layer is in fact zero, and can call .setLayer(15) again to get it to move to the right layer. Obviously a very minor annoyance only if you don't know about this function call ordering quirk.
07/24/2005 (7:53 pm)
Hah, I left out the loadEffect line for brevity and it turns out that's where my problem actually lies. If you call .setLayer() before .loadEffect(), .loadEffect() resets the layer to zero.I was doing:
$emitter = new fxParticleEffect2D() {scenegraph = t2dSceneGraph;};
$emitter.setLayer(15);
$emitter.loadEffect("t2d/client/effects/bubbles.eff");
$emitter.playEffect();And they were all appearing on layer zero. If I echo($emitter.getLayer()) at this point I see that the layer is in fact zero, and can call .setLayer(15) again to get it to move to the right layer. Obviously a very minor annoyance only if you don't know about this function call ordering quirk.
#3
"loadEffect" loads a complete copy of the object from disk which obviously includes the all the effect settings but it also contains much more than that. It also contains details such as size, rotation, position as well as the one you're intertested in, layer. Therefore, when you load the object from disk, you get the copy that you saved and that overwrites ALL previous settings. Not a quirk, this is by design. This means that you don't have to configure rotations, sizes outside the effect. You can load an effect, set its position/layer (or whatever) and play. "Load&Go(tm)"!
In the update, all objects get their own "loadCopy/saveCopy()" that essentially does this action. In-fact, this is a core-call so particle-effects inherit it as well which makes the legacy "load/saveEffect()" deprecated although it'll probably stay for clarity. This is the same case for tile-maps etc.
Hope this helps,
- Melv.
07/25/2005 (5:50 am)
Luke,"loadEffect" loads a complete copy of the object from disk which obviously includes the all the effect settings but it also contains much more than that. It also contains details such as size, rotation, position as well as the one you're intertested in, layer. Therefore, when you load the object from disk, you get the copy that you saved and that overwrites ALL previous settings. Not a quirk, this is by design. This means that you don't have to configure rotations, sizes outside the effect. You can load an effect, set its position/layer (or whatever) and play. "Load&Go(tm)"!
In the update, all objects get their own "loadCopy/saveCopy()" that essentially does this action. In-fact, this is a core-call so particle-effects inherit it as well which makes the legacy "load/saveEffect()" deprecated although it'll probably stay for clarity. This is the same case for tile-maps etc.
Hope this helps,
- Melv.
#4
Thanks. Looking forward to extending this functionality into ther objects too!
07/25/2005 (6:01 am)
Ah, that would explain it. I had considered that the effect had the layer rolled into it, and can certainly see the value of it, I just hadn't come across the docs/source for the load & save calls yet.Thanks. Looking forward to extending this functionality into ther objects too!
#5
It's also worth noting that for the values you cannot change in the particle/tile editors, you shouldn't assume they're set to any particular value although they should be set to default albeit a default that was used when they were originally saved!
Good Luck,
- Melv.
07/25/2005 (6:29 am)
No problem. glad I could help. As I mentioned, the load/save calls will be in the update so you won't have those yet (didn't want you to go searching for them)!It's also worth noting that for the values you cannot change in the particle/tile editors, you shouldn't assume they're set to any particular value although they should be set to default albeit a default that was used when they were originally saved!
Good Luck,
- Melv.
Employee Melv May
I'm can't see any interdependance between "playEffect()" and the layer order. Are you perhaps seeing the sub-layer ordering (which can be set and changed "fxSceneGraph2D::initialise")? There is a sub-order which depends on the creation order of the objects. If you're using another object as a reference point, make sure the object is either created before or after that object dependant upon how you've got your "lastInFrontSorting?" setting in the scenegraph which defaults to true meaning that the last object created appears in front in the layer.
Obviously the above code doesn't work because you need to load an effect or configure one. I tried loading an effect and changing the layer and it seems to work perfectly. The rendering to layers is simply an order thing and is controlled via the scenegraph without it knowing anything about the object.
Let me know your results.
Thanks,
- Melv.