Particles
Blitz3D Forums/Blitz3D Programming/Particles
| ||
Hi, I'd first like to thanks all whom helped me with my last post "fps". i am know working on particles which my system slows my game up, i need a simple example on either how to reuse the particles with a limit on how many can be created for a way to make it run faster in general (i would use one of the other particle systems but they are hard to understand) hope someone can help me. |
| ||
plese can anyone help me, i'm working on a big level and need the particles not to take up so much memory, the particle i am using is snow and it takes up loads of fps off my game. |
| ||
Memory != fps Search the code archives for a "single surface" particle system. Single surface particle systems limit what you can do with the particles, but they'll render most effects much faster than a particle system where each particle is an individual entity. |
| ||
ok thanks for trying to help, the problem is there is far to much coding in that system which makes it out of my reach to understand. |
| ||
Are you saying you don't understand how to use it in your code, or that you don't know how to make one yourself? |
| ||
Click the second link in my signature. Its code should provide you with a fairly good example on how to write a single-surface particle system. |
| ||
Or try RottParticles: http://marksweb.pwp.blueyonder.co.uk/rottbottstudios/rottparticles.html The documentation isn't quite done, but it's pretty easy to use, and very, very fast. |
| ||
goober im in the position at the moment all the demos look great but from a newb point of view they leave me way behind ...at the moment im looking at particle candy http://www.x-pressive.com/ParticleCandy/ looks very very cool but needs some time to learn how to use it, the source code included is NOT documented very well, might just be me still being a newb and not ready for such grown up things... |
| ||
:(, i'd like to say sorry for sounding ungrateful i did not mean it to, i just suck at english, so i hope you can forgive me for that |
| ||
Ok, i had a thought but i dont really know how to do it, using sprites, i was thinking instead of creating them and them destroying them, if i used to for next command to create say 50 sprites and then when they reach the target time for entity it would be repositioned to where it starts, any idea how to do so. |
| ||
I wouldn't say theirs less you can do with them. You can do most of what you can do with sprite particles. It's just a little harder :) |
| ||
Yeah, what you would do, is create a type:Type particle Field entity Field x#,y#,z# Field time Field timer Field alive Field speed End Type Now, at the beginning you create the number of particles you need. Now, when a particle is born, you give it an x,y and z position a speed and set the time you want it to stay onscreen. Also, set the timer field to the millisecs() value so you can check if it's dead. EDIT added in the entity field. You'll need this to store what you want to use as your particle :) Now, whens it's dead, you simply hide it and set the alive field to 0, until a new one needs respawned, or do what you saoid, and move it back to where it comes from and randomise the x,y,z and speed and time fields. When you need to check which ones are currently aviable for respawning, you check the alive field. If it's at zero, then set it to 1 and unhide it :) |
| ||
Ross C i was wanding while i'm coding if i can put my code up to ask if it is correct or not please. |
| ||
Ok man, sure. I'll post this though for you: Small example. Left and right arrow keys to move the emittor: Graphics3D 800,600 SetBuffer BackBuffer() cam=CreateCamera() MoveEntity cam,0,0,-30 Type particle Field entity Field time Field timer Field alive Field speed# End Type Global emittor = CreateSphere() Global emittor_time Global emittor_timer Global number_of_particles = 40 For loop = 1 To number_of_particles p.particle = New particle p\entity = CreateSprite() p\alive=0 Next While Not KeyHit(1) If KeyDown(205) Then MoveEntity emittor,0.1,0,0 If KeyDown(203) Then MoveEntity emittor,-0.1,0,0 update_emittor() update_particles() UpdateWorld RenderWorld Flip Wend End Function update_particles() For p.particle = Each particle MoveEntity p\entity,0,p\speed,0 If MilliSecs() > p\time + p\timer Then p\alive = 0 End If Next End Function Function update_emittor() If MilliSecs() > emittor_time + emittor_timer Then ; check to see if the time has elapsed emittor_timer = MilliSecs() ; reset the spawn timer emittor_time = Rand(10,70) ; randomize the time the next one is generated respawn_particle() ; call the respawn particle function End If End Function Function respawn_particle() For p.particle = Each particle If p\alive = 0 Then ; check to see if a particle is dead. If so, then randomize it's fields and reset it PositionEntity p\entity,EntityX(emittor)+Rnd(-1,1),EntityY(emittor),EntityZ(emittor)+Rnd(-1,1) ; the line above /\ position the particle next to the emittor but randomize it a little p\time = Rand(500,900) p\timer = MilliSecs() p\alive = 1 ; particle is now ALIVE p\speed = Rnd(0.05,0.1) End If Next End Function |
| ||
ok, thanks for the code works well, i only got to see it just know, yesterday i had a go at making my own code but it did not go well here is the code: Type particle Field entity Field x#,y#,z# Field time Field timer Field alive Field speed# End Type Global spr Graphics3D 1280,1024,32,1 SetBuffer BackBuffer() cam=CreateCamera() PositionEntity cam,0,0,-10 For t=1 To 10 spr=CreateSprite() Next While Not KeyHit(1) createpart( Rand(1,2), 0, Rand(1,2), 1, .1) Update RenderWorld Flip Wend End Function createpart( X#, Y#, Z#, Alive, Speed#) p.particle = New particle p\entity = spr p\x# = x# p\y# = y# p\z# = z# PositionEntity p\entity, p\x#, p\y#, p\z# p\alive = alive p\speed# = speed# p\time=1000 p\timer = MilliSecs() End Function Function update() For p.particle = Each particle MoveEntity p\entity, 0, 0+p\speed, 0 If MilliSecs()>p\time+p\timer Then p\alive=0 PositionEntity p\entity,p\x#,p\y-p\y-p\y,p\z EndIf Next End Function i dunno what i have done wring in it apart from almost all of it. |
| ||
All your p\entities are pointing to the same SPR (i.e. the 10th one you create with ... for t = 1 to 10:spr = createsprite():next etc.... You should just use p\entity = createsprite() and remove the above. Sorry but I haven't looked at the rest of the code or tried running it. Stevie |
| ||
For starters you create a new particle every loop which will bring your application to a crawl after a few seconds. try moving the createpart( Rand(1,2), 0, Rand(1,2), 1, .1) line to the line directly under the spr=CreateSprite() line... |