ParticleColor emitter,start_red#,start_green#,start_blue#,start_alpha#,end_red#,end_green#,end_blue#,end_alpha#
Parameters
|
emitter - CPU or GPU particle emitter entity start_red# - red at birth, 0 to 255 start_green# - green at birth, 0 to 255 start_blue# - blue at birth, 0 to 255 start_alpha# - opacity at birth, 0 to 1 end_red# - red at death, 0 to 255 end_green# - green at death, 0 to 255 end_blue# - blue at death, 0 to 255 end_alpha# - opacity at death, 0 to 1 |
Description
|
Sets the colour and opacity a particle fades between over its life. Each particle blends smoothly from the start colour to the end colour as it ages, which is what gives particle effects their character: fire goes from bright yellow to deep red, smoke goes from light grey to near black, and almost everything ends at an alpha of 0 so it fades out instead of popping. A new emitter starts as white fading from fully opaque to fully transparent. Note the two different scales. Red, green and blue use the usual 0 to 255 range you know from EntityColor, but alpha runs 0 to 1 like EntityAlpha. Values outside those ranges are clamped. The colour multiplies whatever texture you put on the emitter with EntityTexture, so one greyscale smoke puff can be tinted into steam, exhaust or poison gas. It also decides how blending reads: with additive blending (EntityBlend 3) a dark end colour fades out on its own, which is why the fire and magic presets look right without sorting. Gotcha: the ramp is driven by how far through its lifetime a particle is, so changing ParticleLifetime changes how fast the colour shifts. Setting the end alpha above 0 leaves particles snapping out of existence at full opacity, which is usually a mistake unless the effect is meant to look like popping sprites. Requires Extended mode. See also: ParticleSize, ParticleLifetime, ParticleSort, EntityBlend, EntityTexture. |
Example
; ParticleColor Example ; --------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,2,-6 CameraClsColor camera,8,12,24 floor=CreatePlane() EntityColor floor,30,34,44 ; A torch flame whose colours fade over each particle's lifetime emitter=CreateParticleEmitter(800) PositionEntity emitter,0,0.5,0 ParticleEmissionRate emitter,150 ParticleLifetime emitter,1,1.8 ParticleVelocity emitter,0,2,0,0.4,0.4,0.4 ParticleSize emitter,0.15,0.03,0.2 EntityBlend emitter,3 ; Fire: bright yellow fading to transparent red ParticleColor emitter,255,220,120,1,255,60,0,0 scheme$="1 fire" While Not KeyDown(1) ; Keys 1-3 pick a start/end colour scheme (RGB 0-255, alpha 0-1) If KeyHit(2) ParticleColor emitter,255,220,120,1,255,60,0,0 scheme$="1 fire (255,220,120,1 -> 255,60,0,0)" EndIf If KeyHit(3) ParticleColor emitter,80,160,255,1,255,80,200,0 scheme$="2 magic (80,160,255,1 -> 255,80,200,0)" EndIf If KeyHit(4) ParticleColor emitter,60,255,80,1,255,255,60,0 scheme$="3 toxic (60,255,80,1 -> 255,255,60,0)" EndIf ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 ; UpdateWorld also advances the particle simulation UpdateWorld RenderWorld Text 0,0,"Arrow keys: move camera 1/2/3: colour scheme Esc: exit" Text 0,20,"ParticleColor scheme: "+scheme$ Flip Wend End
Index