ParticleAnimation emitter,columns,rows[,frames_per_second#][,first_frame][,frame_count][,random_start]
Parameters
|
emitter - CPU or GPU particle emitter entity columns - number of frames across the texture; values below 1 are raised to 1 rows - number of frames down the texture; values below 1 are raised to 1 frames_per_second# (optional) - playback speed; 0 (default) holds a single frame first_frame (optional) - first frame of the range, counting from 0; 0 (default). Clamped to the frames the sheet has frame_count (optional) - how many frames to play from first_frame; 0 (default) uses every remaining frame random_start (optional) - True to start each particle on a random frame of the range; False (default) |
Description
|
Treats the emitter's texture as a sprite sheet and plays it on each particle. This is how you get a flipbook explosion, a rolling smoke puff, a twinkling star or a splash out of one texture. Apply the sheet to the emitter with EntityTexture as usual, then tell ParticleAnimation how it is cut up. Frames are numbered from 0 left to right along the top row, then down - a 4 by 4 sheet has frames 0 to 15, with frame 4 at the start of the second row. Playback is per particle and starts when that particle is born, so each one runs its own copy of the animation and loops back to the start of the range if it lives long enough. That is exactly what you want for a burst of independent explosions from a single emitter. The first_frame and frame_count pair let one sheet hold several effects: put smoke on the top row and sparks on the second, then pick the range you need per emitter. Setting random_start scatters the particles across the range instead of starting them all together, which is the trick for making a bank of embers or a starfield look unsynchronised. Gotcha: leave frames_per_second at 0 and the frame never advances - combined with random_start that gives you a static "pick one sprite from the sheet" emitter, which is a cheap way to vary debris. Loading a ParticlePreset resets the sheet to a single frame, so set the animation after the preset. Requires Extended mode. See also: EntityTexture, ParticleRotation, ParticleLifetime, ParticleRenderMode, ParticlePreset. |
Example
; ParticleAnimation 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 ; Explosion puffs textured with a 6-frame animation strip emitter=CreateParticleEmitter(400) PositionEntity emitter,0,1.5,0 ParticleEmissionRate emitter,25 ParticleLifetime emitter,1,1.5 ParticleVelocity emitter,0,0.8,0,0.8,0.4,0.8 ParticleColor emitter,255,255,255,1,255,255,255,0 ParticleSize emitter,0.4,0.6,0.2 EntityBlend emitter,3 ; The strip is 6 columns x 1 row of explosion frames tex=LoadTexture("../3d_examples/media/kaboom.bmp") EntityTexture emitter,tex fps=12 While Not KeyDown(1) ; [ / ] change the sprite-sheet playback speed If KeyHit(26) And fps>2 Then fps=fps-2 If KeyHit(27) And fps<30 Then fps=fps+2 ; Play frames 0-5 of the 6x1 atlas, each particle starting on a random frame ParticleAnimation emitter,6,1,fps,0,6,True ; 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 [ / ] : playback speed Esc: exit" Text 0,20,"ParticleAnimation emitter,6,1,"+fps+",0,6,True" Flip Wend End
Index