How avoid to excced max num of particles?

Blitz3D Forums/Blitz3D Programming/How avoid to excced max num of particles?

OK, here is a simple demo.

Include "particle candy.bb"

Graphics3D 800,600,32
SetBuffer BackBuffer()

Global look=CreatePivot()
Global cam=CreateCamera(look)
PositionEntity cam,0,150,0
PointEntity cam,look

Dim Particle_Type(100); Up to 100 particle types
InitParticles(cam, "particles.png", 3)
Create_Particle_Types()

Global numemitters=0
Global lasttime=MilliSecs()

While Not KeyHit(1)


;make and explosion every 1/10th second 1000 times
If MilliSecs()-lasttime>100
If numemitters<1000
numemitters=numemitters+1
emitter=CreateEmitter()
Emitter_AddParticleType emitter, Particle_Type(0), 0,10000,20
Emitter_AddParticleType emitter, Particle_Type(1), 0,10000,20
Emitter_AddParticleType emitter, Particle_Type(2), 0,10000,20
Emitter_Start emitter
PositionEntity emitter,Rnd(-50,50),Rnd(-50,50),Rnd(-50,50)
lasttime=MilliSecs()
EndIf
EndIf 


UpdateParticles

TurnEntity look,1,1,1,1

UpdateWorld()
RenderWorld()
Text 0,0,"Emitters "+numemitters
Text 0,15,"Particles "+pt_numParticles
Flip



Wend

FreeParticleSystem ()


Function Create_Particle_Types% ()
;Red Smoke
Particle_Type(0) = CreateParticleType()
ParticleType_SetImage    		  Particle_Type(0),9
ParticleType_SetSpeed    		  Particle_Type(0),80,0
ParticleType_SetRandomSpeed	  Particle_Type(0),.02,0,.02
ParticleType_SetSize     		  Particle_Type(0),2,1,4,7
ParticleType_SetAlpha    		  Particle_Type(0),.5,.2,-.25
ParticleType_SetWeight   		  Particle_Type(0),0,0
ParticleType_SetRotation 		  Particle_Type(0),1,0
ParticleType_SetColor    		  Particle_Type(0),255,50,50,0,0,0,0
ParticleType_SetEmissionAngle Particle_Type(0),3,360
ParticleType_SetStartOffsets  Particle_Type(0),0,0,0,0,0,0
ParticleType_SetLifeTime 		  Particle_Type(0),250
ParticleType_SetAddedBlend    Particle_Type(0),0
;FireBall
Particle_Type(1) = CreateParticleType()
ParticleType_SetImage    		  Particle_Type(1),5
ParticleType_SetSpeed    		  Particle_Type(1),0,0
ParticleType_SetSize     		  Particle_Type(1),2,0,-2
ParticleType_SetAlpha    		  Particle_Type(1),1,0,0
ParticleType_SetWeight   		  Particle_Type(1),0,0
ParticleType_SetRotation 		  Particle_Type(1),1,0
ParticleType_SetColor    		  Particle_Type(1),255,255,200,0,-200,-200,-200
ParticleType_SetEmissionAngle Particle_Type(1),0,1
ParticleType_SetStartOffsets  Particle_Type(1),0,0,0,0,0,0
ParticleType_SetLifeTime 		  Particle_Type(1),2500
ParticleType_SetBounce        Particle_Type(1),0,0,0
ParticleType_SetPulsation     Particle_Type(1),4
ParticleType_SetAddedBlend    Particle_Type(1),0
; SPARKS
Particle_Type(2) = CreateParticleType()
ParticleType_SetImage    		  Particle_Type(2),1
ParticleType_SetSpeed    		  Particle_Type(2),15,5
ParticleType_SetSize     		  Particle_Type(2),.5,.15,-.5
ParticleType_SetAlpha    		  Particle_Type(2),1,.25,-.18
ParticleType_SetWeight   		  Particle_Type(2),2,0
ParticleType_SetRotation 		  Particle_Type(2),2,0
ParticleType_SetColor    		  Particle_Type(2),255,246,149,20,-150,-200,-150
ParticleType_SetEmissionAngle Particle_Type(2),3,360
ParticleType_SetStartOffsets  Particle_Type(2),0,0,0,0,0,0
ParticleType_SetLifeTime 		  Particle_Type(2),2000
ParticleType_SetBounce        Particle_Type(2),0,0,0
ParticleType_SetPulsation     Particle_Type(2),0
ParticleType_SetAddedBlend    Particle_Type(2),0
End Function


The key is to create an emitter for every bomb but do not create individual particles types for each bomb.

You only create the particle types once and then each emitter uses the same ones.