Hey, i'm trying to make some partical effects, one of them is a partical explosion.
Basicly, you create it, at [blank] point using [blank] image, using [blank] amount of particals, and a max travel distance is set (imagine a circle around the start point). Each partical is then assigned a direction randomly generated. Then, this is where I'm stumped, you set the partical alpha according to how much distance it traveled.
I have two problems:
1. How to calculate the alpha setting, where 1 (fully solid) being at the beginning point, and 0 (completely transparent) being at the max distance (imaginary circle around the start point)
2. How to calculate how much distance the partical has traveled (i'm having trouble becase it doesnt just travel on one axis. And because it can be going any direction)
Here is my code at the moment:
Any help appriciated!
Basicly, you create it, at [blank] point using [blank] image, using [blank] amount of particals, and a max travel distance is set (imagine a circle around the start point). Each partical is then assigned a direction randomly generated. Then, this is where I'm stumped, you set the partical alpha according to how much distance it traveled.
I have two problems:
1. How to calculate the alpha setting, where 1 (fully solid) being at the beginning point, and 0 (completely transparent) being at the max distance (imaginary circle around the start point)
2. How to calculate how much distance the partical has traveled (i'm having trouble becase it doesnt just travel on one axis. And because it can be going any direction)
Here is my code at the moment:
Global ParticalList:TList = CreateList() Global ParticalExpList:TList = CreateList() Type TPartical Field x:Int,y:Int,a:Float,r:Int Field d_x:Int,d_y:Int Field img:TImage Field dist_traveled:Int Field ID:String Method Create(_id:String,x:Int,y:Int,_img:TImage,_d_x:Int = 0,_d_y:Int = 0) ListAddLast(ParticalList,Self) x = _x y = _y img = _img ID = _id End Method Method Update() x:+d_x y:+d_y dist_traveled:+(d_x+d_y) SetRotation(r) SetAlpha(a) DrawImage img,x,y SetRotation(0) SetAlpha(1) End Method Method SetAlpha(alpha:Float) a = alpha End Method Method SetRotation(rot:Int) r = rot End Method Method Destroy() ParticalList.Remove(Self) End Method End Type Type TParticalExp Field part_n:Int,part_img:TImage Field dist:Int Field x:Int,y:Int Field d_x:Int,d_y:Int Method Create(_x:Int,_y:Int,_part_img:TImage,_part_n:Int,dist:Int) ListAddLast(ParticalExpList,Self) part_n = _part_n part_img = _part_img x = _x y = _y d_x = Rand(-3,3) d_y = Rand(-3,3) For Local i:Int = 1 To part_n Local part:TPartical = TPartical.Create("pexp",x,y,part_img,d_x,d_y) Next End Method Method Update() For Local i:TPartical = EachIn ParticalList If i.ID = "pexp" If i.dist_traveled > i.SetAlpha(i. i.Update() End If End Type
Any help appriciated!