Particles In Code: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(→‎SDK Bug: to bug template, made link internal)
(direct dispatching)
Line 1: Line 1:
== Precaching Effects ==
{{toc-right}}


Before dispatching effects, you should precache them first. This can be done by listing them in your <code>particles_manifest.txt</code> file, or with this code:
== Precaching ==
 
Particle effects must be [[precache]]d before they can be used. This is done by listing them in <code>[[particles_manifest.txt]]</code>, then making this call:


<source lang=cpp>PrecacheParticleSystem( "your_particle_effect_name" );</source>
<source lang=cpp>PrecacheParticleSystem( "your_particle_effect_name" );</source>


== Dispatching Effects ==
== Dispatching ==


At the very simplest you can just kick off an effect with the Dispatch function:
Particles systems are "dispatched" on the client.


<source lang=cpp>void DispatchParticleEffect( const char *pszParticleName, Vector vecOrigin, QAngle vecAngles,
{{tip|You can stop all systems tied to a given entity with <code>StopParticleEffects( CBaseEntity* pEntity )</code>. But you cannot otherwise control the lifespan of a system from code. It will self-terminate on its own internal schedule.}}
CBaseEntity *pEntity )
void DispatchParticleEffect( const char *pszParticleName, ParticleAttachment_t iAttachType,
CBaseEntity *pEntity, int iAttachmentPoint,
bool bResetAllParticlesOnEntity  )</source>


The former signature lets you just place it arbitrarily in world coordinates. The latter permits you to attach it to an entity. You may then stop effects on an entity with this function:
=== Simple ===


<source lang=cpp>StopParticleEffects( CBaseEntity *pEntity )</source>
<source lang=cpp>
#include "particle_parse.h"


You cannot specify a lifetime on a particle system from code. The system will self-terminate after the lifespan specified in the particle definition.
void DispatchParticleEffect( const char *pszParticleName, Vector vecOrigin, QAngle vecAngles, CBaseEntity *pEntity )
void DispatchParticleEffect( const char *pszParticleName, ParticleAttachment_t iAttachType, CBaseEntity *pEntity,
int iAttachmentPoint, bool bResetAllParticlesOnEntity  )</source>


DispatchParticleEffect particles is only visible to you if run from client-side.
The first function creates the system at some arbitrary world co-ordinates. The second spawns it at an [[attachment]].


{{bug|Valve's code for dispatching a particle attached to a model is broken. [[SDK Known Issues List Fixed#Server Dispatching an Attached Particle Effect|Get the fix here.]]}}
{{bug|Valve's code for dispatching a particle attached to a model is broken. [[SDK Known Issues List Fixed#Server Dispatching an Attached Particle Effect|Get the fix here.]]}}
=== Complex ===
If you need to control the system after it spawns, the helper functions above won't do. Instead:
<source lang=cpp>
#include "particles_new.h"
CNewParticleEffect* pEffect = ParticleProp()->Create( "rail_shot", PATTACH_ABSORIGIN );
pEffect->SetControlPoint( 1, vecSomeVector );
</source>
See also <code>[[CNewParticleEffect]]</code>.


[[Category: Particle System]]
[[Category: Particle System]]

Revision as of 15:48, 20 October 2009

Precaching

Particle effects must be precached before they can be used. This is done by listing them in particles_manifest.txt, then making this call:

PrecacheParticleSystem( "your_particle_effect_name" );

Dispatching

Particles systems are "dispatched" on the client.

Tip.pngTip:You can stop all systems tied to a given entity with StopParticleEffects( CBaseEntity* pEntity ). But you cannot otherwise control the lifespan of a system from code. It will self-terminate on its own internal schedule.

Simple

#include "particle_parse.h"

void DispatchParticleEffect( const char *pszParticleName, Vector vecOrigin, QAngle vecAngles, CBaseEntity *pEntity )
void DispatchParticleEffect( const char *pszParticleName, ParticleAttachment_t iAttachType, CBaseEntity *pEntity, 
				int iAttachmentPoint, bool bResetAllParticlesOnEntity  )

The first function creates the system at some arbitrary world co-ordinates. The second spawns it at an attachment.

Icon-Bug.pngBug:Valve's code for dispatching a particle attached to a model is broken. Get the fix here.  [todo tested in ?]

Complex

If you need to control the system after it spawns, the helper functions above won't do. Instead:

#include "particles_new.h"

CNewParticleEffect* pEffect = ParticleProp()->Create( "rail_shot", PATTACH_ABSORIGIN );

pEffect->SetControlPoint( 1, vecSomeVector );

See also CNewParticleEffect.