Amon, this works...
You have to remove the particle from the list rather than making the type instance null. I changed the code to have the loop in the mainloop which, I think, is better. I didn't change any of the others though.
<edit> I also changed the coord check to one line as I was getting errors.
Strict Graphics 1024,768,16,0 Global particle_count:Int = 0 Global maxparticles:Int = 100 Global direction:Int = Rand(0,360) Global mx:Int, my:Int SeedRnd MilliSecs() SetMaskColor 255,0,255 AutoMidHandle True Global particles:TImage = LoadImage("particle.png",MASKEDIMAGE) SetImageFont Null Type particle Global particle_list:TList Field x:Int, y:Int, d:Int, s:Int Function create() If particle_list = Null particle_list = CreateList() If MouseDown( KEY_MOUSELEFT) Local p:particle = New particle p.x = mx p.y = my p.d = Rand(0,360) p.s = Rand(4,20) ListAddLast particle_list,(p) EndIf End Function Method draw() For Local p:particle = EachIn particle_list DrawImage particles,p.x,p.y,0 Next End Method Function update() For Local p:particle = EachIn particle_list p.x = Sin(p.d) * p.s + p.x p.y = Cos(p.d) * p.s + p.y Next End function Method destroy() If x > 1030 Or x < -2 Or y > 780 Or y < -2 ListRemove(particle_list,Self) EndIf Rem If p.y > 780 Or p.y < -2 p = Null EndIf End Rem End Method End Type Repeat Cls mx = MouseX() my = MouseY() particle.create() If particle.particle_list For Local p:particle = EachIn particle.particle_list p.draw() Next EndIf particle.update() If particle.particle_list For Local p:particle = EachIn particle.particle_list p.destroy() Next EndIf FlushMem DrawText MemAlloced(),0,0 Flip Until KeyHit(KEY_ESCAPE)
You have to remove the particle from the list rather than making the type instance null. I changed the code to have the loop in the mainloop which, I think, is better. I didn't change any of the others though.
<edit> I also changed the coord check to one line as I was getting errors.