I thought id share my fire function with the community, it takes all the dirty work out of making fire for torches campfires and candles it comes complete with particles fire and smoke.
simply download the attached file and drop it into your project folder
then in your main project add these lines
#include "fire.agc"
`loads images in a numbered series
Load_fire()
` (particle number,objectnumber, number of images to use,size) "images provided!"
createobjectbox(1,.1,.1,.1)
makefire(1,1,4,4)
Do
`(particle number,objectnumber)
move_fire(1,1)
sync()
loop
this will create a smoke cloud, spark particles and moving flames, it has a built in offset to keep the sprites from running all over the place as the camera moves and the screen xy coods change. i
hope this helps someone enjoy
torch code separate below
function Load_fire()
global particlesreserved as integer:particlesreserved=95
global firestepper as integer
firestepper=100
global oldfirex as integer[10]
global newfirex as integer[10]
global oldfirey as integer[10]
global newfirey as integer[10]
LoadImage (16,"particle.png")
for i = 100 to 104
loadimage(i,"fire"+str(i-99)+".png")
next
endfunction
function makefire(partid,objID,imagenums,size)
`spark particles
global imgnums
imgnums=imagenums
CreateParticles ( objID, 150, 10 )
SetParticlesImage ( objID, 16 )
SetParticlesStartZone ( objID, -2, -1, 2, 1 )
SetParticlesDirection ( objID, 0, 50.0*size )
SetParticlesLife ( objID, 4 )
SetParticlesSize ( objID, 2*size )
SetParticlesAngle ( objID, 30 )
SetParticlesFrequency ( objID, .3 )
SetParticlesVelocityRange ( objID, 1, 4 )
AddParticlesColorKeyFrame ( objID, 0, 255, 255, 55, 255 )
AddParticlesColorKeyFrame ( objID, .5, 255, 255, 50, 200 )
AddParticlesColorKeyFrame ( objID, 3.0, 50, 50, 50, 100 )
AddParticlesColorKeyFrame ( objID, 4.0, 0, 0, 0, 0 )
`blacksmoke
CreateParticles (objID+1,GetScreenXFrom3D(getobjectx(objID), getobjecty(objID), getobjectz(objID)),GetScreenyFrom3D(getobjectx(objID), getobjecty(objID), getobjectz(objID)))
SetParticlesImage ( objID+1, 16 )
SetParticlesStartZone ( objID+1, -2, 5, 2, 9 )
SetParticlesDirection ( objID+1, 0, -50.0*size )
SetParticlesLife ( objID+1, 4 )
SetParticlesSize ( objID+1, 20*size )
SetParticlesAngle ( objID+1, 20 )
SetParticlesFrequency ( objID+1, 20 )
SetParticlesVelocityRange ( objID+1, 1, 4 )
AddParticlesColorKeyFrame ( objID+1, 0, 55, 55, 55, 85 )
AddParticlesColorKeyFrame ( objID+1, .5, 55, 55, 55, 50 )
AddParticlesColorKeyFrame ( objID+1, 3.0, 10, 10, 10, 25 )
AddParticlesColorKeyFrame ( objID+1, 4.0, 0, 0, 0, 0 )
`load fire images create 4 particles for rnd fire effect.
for i=particlesreserved+(partid*4)+partid to particlesreserved+imgnums+(partid*4)+partid
CreateParticles ( i, 150, 10 )
SetParticlesImage ( i, firestepper)
SetParticlesStartZone ( i, -1*size, 1*size, 1*size, 1*size )
SetParticlesDirection ( i, 0, -40.0*size )
SetParticlesLife ( i, .4 )
SetParticlesSize ( i, 9 *size)
SetParticlesAngle ( i, 0 )
SetParticlesFrequency ( i, 13*size)
AddParticlesColorKeyFrame ( i, .1, 255, 255, 55, 255 )
AddParticlesColorKeyFrame ( i, .2, 255, 255, 55, 155 )
AddParticlesColorKeyFrame ( i, .2, 255, 255, 55, 75 )
AddParticlesColorKeyFrame ( i, .4, 155, 155, 55, 25 )
SetParticlesVelocityRange ( i, .5, 2 )
if firestepper < imgnums+100
inc firestepper, 1
else
firestepper=100
endif
next
endfunction
function move_fire(partid,objID)
oldfirex[partid]=GetScreenXFrom3D(getobjectx(objID), getobjecty(objID), getobjectz(objID))
oldfirey[partid]=GetScreenyFrom3D(getobjectx(objID), getobjecty(objID), getobjectz(objID))
for i=particlesreserved+(partid*4)+partid to particlesreserved+imgnums+(partid*4)+partid
OffsetParticles(i,(oldfirex[partid]-newfirex[partid]),oldfirey[partid]-newfirey[partid])
next
OffsetParticles(objID+1,(oldfirex[partid]-newfirex[partid]),oldfirey[partid]-newfirey[partid])
newfirex[partid]=GetScreenXFrom3D(getobjectx(objID), getobjecty(objID), getobjectz(objID))
newfirey[partid]=GetScreenyFrom3D(getobjectx(objID), getobjecty(objID), getobjectz(objID))
for i=particlesreserved+(partid*4)+partid to particlesreserved+imgnums+(partid*4)+partid
SetParticlesPosition(i,newfirex[partid],newfirey[partid])
SetParticlesPosition(objID,GetScreenXFrom3D(getobjectx(objID), getobjecty(objID), getobjectz(objID)),GetScreenyFrom3D(getobjectx(objID), getobjecty(objID), getobjectz(objID)))
SetParticlesPosition(objID+1,newfirex[partid],newfirey[partid])
next
endfunction
EDIT: side not if you want more then one torch of fire add a seperate object for it to get xyz coord from but object number i believe needs to be 2 higher in number then the previous since it add images for smoke and particles. based off object id.
A child's dream never dies.