Blitz3D+ Command Reference

ParticleLifetime emitter,minimum#[,maximum#]

Parameters

emitter - CPU or GPU particle emitter entity

minimum# - shortest lifetime in seconds; values below 0.001 are raised to 0.001

maximum# - longest lifetime in seconds; -1 (default) means "same as minimum". A maximum below the minimum is raised to the minimum

Description

Sets how long each new particle lives.

Every particle picks its own lifetime at random between the two values, which is what stops an effect looking mechanical. Give a campfire a range like 0.4 to 1.1 and the flames flicker; give it a single fixed value and the whole plume pulses in step.

Lifetime does more than decide when a particle disappears. The colour ramp from ParticleColor, the size ramp from ParticleSize and the sprite-sheet animation from ParticleAnimation are all driven by how far through its life a particle is, so shortening the lifetime speeds all of them up.

It is also the other half of your particle budget. Roughly, lifetime multiplied by ParticleEmissionRate is how many particles will be alive at once, so doubling the lifetime doubles the number you need to allow for in ParticleMax.

Gotcha: seconds are simulated seconds. The simulation is advanced by UpdateWorld, whose default tick is one 60 Hz step, so a lifetime of 2 lasts two real seconds only if you call UpdateWorld about 60 times a second. Passing just a minimum gives every particle exactly that lifetime.

Requires Extended mode.

See also: ParticleEmissionRate, ParticleColor, ParticleSize, ParticleMax, ParticlePreset.

Example

; ParticleLifetime 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 rocket exhaust plume - lifetime decides how long the trail is
emitter=CreateParticleEmitter(1500)
PositionEntity emitter,0,0.5,0
ParticleEmissionRate emitter,250
ParticleVelocity emitter,0,3,0,0.4,0.3,0.4
ParticleColor emitter,255,220,120,1,255,80,0,0
ParticleSize emitter,0.12,0.03,0.2
EntityBlend emitter,3

life_min#=0.5
life_max#=1.5

While Not KeyDown(1)

    ; [ / ] shrink or stretch the random lifetime range in seconds
    If KeyDown(26) And life_min>0.2 Then
        life_min=life_min-0.02
        life_max=life_max-0.04
    EndIf
    If KeyDown(27) And life_max<5 Then
        life_min=life_min+0.02
        life_max=life_max+0.04
    EndIf

    ; Each new particle lives between life_min and life_max seconds
    ParticleLifetime emitter,life_min,life_max

    ; 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   [ / ] : lifetime range   Esc: exit"
    Text 0,20,"ParticleLifetime emitter,"+life_min+","+life_max
    Text 0,40,"Live particles: "+CountParticles(emitter)+" (longer life = taller plume)"

    Flip

Wend

End

Index