I'm currently working a little project which goal is to facilitate the adding of Particle Systems.
I'm using a function called initPartSyst() that demands all the useful informations for a Particle Sytsem (x, y, buffer, time, ...)
The problems come with the colors part. To parameter the color of a Particle System, you must use ps:setColors(color1, color2,...) which can take 4-long tables as input.
My question is this: Can I put all those tables in a big table and use it as arguments?
![Huuh... :huh:](./images/smilies/ms-huh.png)
I put the code so you can see why I'm asking this more in detail:
Code: Select all
function love.load()
img = love.graphics.newImage("Textures/particle.png")
emitters = {}
end
function love.update(dt)
for i,v in ipairs(emitters) do
v:update(dt)
end
end
function love.draw()
love.graphics.setBlendMode("add")
for i,v in ipairs(emitters) do
love.graphics.draw(v)
end
end
function love.mousepressed(x, y, button)
if button == 1 then table.insert(emitters, initPartSys(img, x, y, 1500, 0.1, 0.5, -200, -2000, 200, 100, 3000, {234, 217, 30, 128, 255, 0, 0, 0})) end --Fire
if button == 2 then table.insert(emitters, initPartSys(img, x, y, 1500, 0.1, 0.5, -200, -100, 200, 2000, 3000, {1, 255, 255, 128, 0, 0, 255, 0})) end --Water
if button == 3 then table.insert(emitters, initPartSys(img, x, y, 1500, 0.1, 0.5, -500, -500, 500, 500, 3000, {255, 255, 255, 255, 255, 255, 255, 0})) end --Smoke
end
function initPartSys(image, x, y, maxParticles, mintime, maxtime, minx, miny, maxx, maxy, rate, colors)
local ps = love.graphics.newParticleSystem(image, maxParticles)
ps:setPosition(x, y)
ps:setParticleLifetime(mintime, maxtime)
ps:setSizeVariation(1)
ps:setEmissionRate(rate or 100)
ps:setLinearAcceleration(minx, (miny or minx), maxx, (maxy or maxx))
colorarg = {}
for i=0,#colors - 1 do
if i%4 == 0 then table.insert(colorarg, {}) end --Add a new color array every 4 variables
table.insert(colorarg[math.floor(i/4)+1], colors[i+1]) --Insert each variable of colors in the proper color array
end
ps:setColors(colorarg) -- Colorarg contains the informations of colors, segmented in multiples 4-long tables.
return ps
end
If a solution exists (not necessarily what I've planned, it can be another way to do it), I'll be glad to know it
![Glee ^^](./images/smilies/ms-glee.png)