How can I attach a particle effect to an object?
by Zilla · in Torque X 2D · 08/29/2007 (2:05 pm) · 19 replies
How can I "attach"/"mount"/"trigger" a particle effect to an non-static object?
For example: smoke that appears when the player explodes.
I know how to do it with animations but not with particle effects.
For example: smoke that appears when the player explodes.
I know how to do it with animations but not with particle effects.
#2
09/04/2007 (9:28 am)
@Zilla - I'm not sure I understand the question. Is there a reason you can't do it the same way you do it with animations?
#3
First, I create an emitter, name it SmokeEmitter and mark it as a template.

Then I want this emitter as the drill's dying animation, but the name SmokeEmitter does not appear on the dropdown list.

Another example: In the Blaster tutorial, I want that the explosion is not an animation but an emitter
09/04/2007 (2:22 pm)
Quote:I'm not sure I understand the question.Oops... I know that my English is very limited so I try to explain it with an example where I can use some images. I will use the Platformer Kit.
First, I create an emitter, name it SmokeEmitter and mark it as a template.

Then I want this emitter as the drill's dying animation, but the name SmokeEmitter does not appear on the dropdown list.

Another example: In the Blaster tutorial, I want that the explosion is not an animation but an emitter
#4
09/04/2007 (2:51 pm)
@Zilla - I'm not an expert on the platformer kit, but it looks to me like what that is trying to do is switch an existing T2DAnimatedSprite to use a different T2DAnimationData based on some kind of state machine. Creating a new object (such as a clone of your particle effect) would be a different thing -- some of the tutorials do something like that when they create a clone of an explosion animation and play it where the original object used to be. If you were doing something like that, there wouldn't be much difference between the explosion animation and the particle effect.
#5
In the blaster tutorial, does it not work if you just use the name of your particle effect template instead of the name of your explosion template?
09/04/2007 (2:53 pm)
Woops, started posting before I saw the edit.In the blaster tutorial, does it not work if you just use the name of your particle effect template instead of the name of your explosion template?
#6
I wish it were that easy... It didn't work... You mentioned it in the previous post: the particle effect doesn't like to be called "T2DAnimatedSprite".
09/05/2007 (7:05 am)
@DanI wish it were that easy... It didn't work... You mentioned it in the previous post: the particle effect doesn't like to be called "T2DAnimatedSprite".
#7
09/05/2007 (7:33 am)
Try T2DParticleEffect. Or if you want it to work for either particle effects or animated sprites, use T2DSceneObject. That code doesn't use any T2DAnimatedSprite or T2DParticleEffect specific stuff, so there's no downside to using the more general T2DSceneObject instead.
#8
You most probably want to use T2DParticleEffect instead of T2DAnimatedSprite, and you will probably want to play around with resetting and/or playing the effect from the start once you move it.
Keep in mind, since your original question was "how do I mount a particle effect", that since T2DParticleEffect is a subclass of T2DSceneObject, it can be mounted to other objects just like any other scene object.
09/05/2007 (7:41 am)
That's because particle effects are not animations, they are particle effects :)You most probably want to use T2DParticleEffect instead of T2DAnimatedSprite, and you will probably want to play around with resetting and/or playing the effect from the start once you move it.
Keep in mind, since your original question was "how do I mount a particle effect", that since T2DParticleEffect is a subclass of T2DSceneObject, it can be mounted to other objects just like any other scene object.
#9
09/05/2007 (8:27 am)
Quote:You most probably want to use T2DParticleEffectYES! Thank you very much for your help :-)))
#10
09/05/2007 (9:10 am)
Unfortunately, it seems that it is not that simple to modify the platformer kit:
#11
You seem to be wanting to change the scene to be loaded, and that is absolutely possible, so it must be some form of typo, or incorrect file name for your scene level.
09/05/2007 (9:27 am)
Unfortunately, your error is in german, and we can't see what the error is, but most probably it's just not reading the file correctly.You seem to be wanting to change the scene to be loaded, and that is absolutely possible, so it must be some form of typo, or incorrect file name for your scene level.
#12
System.ArgumentException was unhandled
Message="Das Objekt mit dem Typ GarageGames.Torque.T2D.T2DParticleEffect kann nicht in den Typ GarageGames.Torque.T2D.T2DAnimationData konvertiert werden."
My English is not very good but I try to translate it:
"The object type GarageGames.Torque.T2D.T2DParticleEffect cannot be converted into GarageGames.Torque.T2D.T2DAnimationData"
09/05/2007 (11:14 am)
The error message says:System.ArgumentException was unhandled
Message="Das Objekt mit dem Typ GarageGames.Torque.T2D.T2DParticleEffect kann nicht in den Typ GarageGames.Torque.T2D.T2DAnimationData konvertiert werden."
My English is not very good but I try to translate it:
"The object type GarageGames.Torque.T2D.T2DParticleEffect cannot be converted into GarageGames.Torque.T2D.T2DAnimationData"
#13
As I said, I'm not an expert on the platformer kit, but it seems like what you ought to by trying to do is to find the state machine transition that causes the death animation to play. Instead of trying to replace the death animation with something else, just create a new particle effect on top of the sprite, like you did in the blaster tutorial.
09/05/2007 (12:35 pm)
@Zilla - It's not 100% clear exactly what you're doing wrong, but it sounds like you're trying to use a particle effect as a T2DAnimationData, which won't work. You may not be appreciating the difference between a T2DAnimatedSprite (a scene object that can play animations) and T2DAnimationData (an animation that can be played by an animated sprite). In the blaster tutorial, you are creating a new T2DAnimatedSprite by cloning your explosion template, which is itself a T2DAnimatedSprite. The Platformer kit component that you're using works with an existing animated sprite (in this case, the drill), and switches the animation it is playing. An animated sprite can't "play" a particle effect -- that's not something that makes sense.As I said, I'm not an expert on the platformer kit, but it seems like what you ought to by trying to do is to find the state machine transition that causes the death animation to play. Instead of trying to replace the death animation with something else, just create a new particle effect on top of the sprite, like you did in the blaster tutorial.
#14
Topic: Replace a death animation with a particle effect
Dan is correct about the ActorAnimationManager in the Platformer kit. It allows you to specify different animation data for specific pre-defined states and then automatically transitions between them as specified by rules defined in the states themselves. The key thing to note here, though, is that it's still only swapping out different animation data on a single animated sprite, rather than creating different animated sprites whenever a state changes.
There's a full example in the above link for those interested. For those of you without access to the Platformer Kit forums, the solution (as Dan suggested) is to simply set the player invisible and then spawn a clone of your particle effect template when the player dies.
09/05/2007 (8:30 pm)
Quick update: I got an email from Zilla and decided to create a thread detailing exactly how to use a particle effect instead of an animation for player death in the following thread in the Platformer Starter Kit forums:Topic: Replace a death animation with a particle effect
Dan is correct about the ActorAnimationManager in the Platformer kit. It allows you to specify different animation data for specific pre-defined states and then automatically transitions between them as specified by rules defined in the states themselves. The key thing to note here, though, is that it's still only swapping out different animation data on a single animated sprite, rather than creating different animated sprites whenever a state changes.
There's a full example in the above link for those interested. For those of you without access to the Platformer Kit forums, the solution (as Dan suggested) is to simply set the player invisible and then spawn a clone of your particle effect template when the player dies.
#15
if (enemy.HitPoints <= 0) {
theirObject.MarkForDelete = true;
if (enemy.DestructionEffect != null) {
T2DSceneObject effect = enemy.DestructionEffect.Clone() as T2DSceneObject;
effect.Position = theirObject.Position;
TorqueObjectDatabase.Instance.Register(effect);
}
if (enemy.OnDestruction != null) {
enemy.OnDestruction(theirObject);
}
}
This way the destruction effect can be set to an object of choosing in TXB. I followed one of the new tutorials to do this, the space warrior tutorial has more info.
So if anyone knows how to not have the particle effect start up right at the beginning, do tell.
(SORRY THE FORMATTING ON THE CODE DOSNT SEEM TO WORK)
10/24/2007 (8:55 am)
Hey, all, I actually got the particle effect to work when something dies, but my problem is a little different. How do I get this particle effect to not go when the level starts up. Here is my solution to doing this: if (enemy.HitPoints <= 0) {
theirObject.MarkForDelete = true;
if (enemy.DestructionEffect != null) {
T2DSceneObject effect = enemy.DestructionEffect.Clone() as T2DSceneObject;
effect.Position = theirObject.Position;
TorqueObjectDatabase.Instance.Register(effect);
}
if (enemy.OnDestruction != null) {
enemy.OnDestruction(theirObject);
}
}
This way the destruction effect can be set to an object of choosing in TXB. I followed one of the new tutorials to do this, the space warrior tutorial has more info.
So if anyone knows how to not have the particle effect start up right at the beginning, do tell.
(SORRY THE FORMATTING ON THE CODE DOSNT SEEM TO WORK)
#16
10/24/2007 (11:09 am)
@Matt - The particle effect will start going as soon as it's registered. So if you want it to start later, make it a template, and create a clone that you register later, just like you're doing here. Is there some specific time that you want it to go off? If so, you could try scheduling a method to start it at that time. Is it supposed to go off as a result of some event? That's what you're doing here when you start the particle effect when the ship dies. It's hard to understand what you're having trouble with.
#17
10/25/2007 (7:18 am)
So I have placed my particle emitter in this level in TXB and I dont want it to emit anything until the enemy dies. So in this case, how do I not register the particle emitter or have it emit anything until the enemy dies?
#18
When the enemy dies, clone and register the object just like in the code snippet you posted.
Is this answering your question?
10/25/2007 (9:25 am)
In TXB, mark it as a template. This will keep it from being registered into the scene at startup.When the enemy dies, clone and register the object just like in the code snippet you posted.
Is this answering your question?
#19
10/25/2007 (10:27 am)
Definitely, thanks for your help.
Torque Owner Zilla
Is there an example that I could analyze where a particle effect is used on a moving object?