How do you make fire?

Blitz3D Forums/Blitz3D Beginners Area/How do you make fire?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

well in particles such as fire and smoke you can use sprites but also meshes, to make them you need to use types and functions (well that's the best way), and just make one function to create the particles and another to update the movement of them. and example of some code below:

FlushKeys()
Print "Press the up arrow to generate particles."
Print
Print "press any key to continue!"
WaitKey()


Graphics3D 800,600
SetBuffer BackBuffer()

Global cam=CreateCamera()
PositionEntity cam,0,5,-50

Global sprite=LoadSprite("s1.png",4)
HideEntity sprite



Global no_parts=0


Type part
Field entity
Field entity1
Field time#
Field timer
Field speed#
End Type

While Not KeyHit(1)

; limit the number of particles made
If KeyDown(200) And no_parts<100 Then create_part(0,0,0,Rnd(-110,-70),Rnd(-180,180),Rnd(0.1,0.3))

update_parts() ; update the particles
UpdateWorld
RenderWorld
Flip
Wend
End

Function create_part(x#,y#,z#,pitch#,yaw#,speed#)
no_parts=no_parts+1 ; keep count of the particles
p.part=New part
p\entity=CopyEntity(sprite) ; copy the main sprite, into the type field
ScaleSprite p\entity,2,3 ; scale the particle
PositionEntity p\entity,x,y,z ; position the particle to the passed co-ords
RotateEntity p\entity,pitch#,yaw#,0 ; rotate the particles, so they have slightly different directions
EntityBlend p\entity,3 ; important for the glow effect. Set the blend mode fro the entity

p\time=Rand(1000,1000); give the particle a life span
p\timer=MilliSecs() ; take note of the value of millisecs()

p\speed=speed ; copy the speed to the type field
End Function

Function update_parts()
For p.part=Each part
MoveEntity p\entity,0,0,p\speed
EntityAlpha p\entity,(1-((MilliSecs()-p\timer)/p\time))*0.2; work out the alpha, based on the entitys remaining life span
; /\ the 0.2 makes the alpha start at a low value, and fade out. 0.2 because the blend effect is too much, with lower alpha values
If MilliSecs()>p\time+p\timer Then; if particle is nearing the end of its life

FreeEntity p\entity; free the entity

Delete p.part; delete the particle type reference
no_parts=no_parts-1 ; keep track of the number of entitys

End If
Next
End Function

Hope this helps.