Page 2 of 2

### Re: Independent Particle Colors

Posted: Thu Oct 31, 2019 5:22 pm
JJSax wrote:
Wed Oct 30, 2019 5:59 pm
kicknbritt wrote:
Wed Oct 30, 2019 9:13 am
Why dont you just make a table that holds all the confetti particles, update all of them for things like movement of the confetti particles and then draw all of them using a SpriteBatch, setting thier individual colors with SpriteBatch:setColor( r, g, b, a )?
You mean something like creating a table of love.graphics.newParticleSystem()? Or do something outside of love2d's particle system entirely?
Sorry, I really thought setQuads would use them randomly, not with the lifetime.
And kicknbritt also means the alternative I wrote above, so it might be the best solution: don't use the inbuilt particle system, make one yourself.

Here is one, rather basic and not optimized.

Code: Select all

``````particles = { }
spritebatch = love.graphics.newSpriteBatch(yourSprite, 256, "dynamic")

function newParticle(x, y)
table.insert(particles, {
color = {math.random(), math.random(), math.random()},
x = x,
y = y,
ax = math.random()-0.5,
ay = math.random()-0.5,
rot = math.random()*math.pi*2,
})
end

function drawParticles()
spritebatch:clear()
for d,s in ipairs(particles) do
spritebatch:setColor(s.color)
spritebatch:add(s.x, s.y, s.rot, 1.0, 1.0, yourSprite:getWidth()/2, yourSprite:getHeight()/2)
end
love.graphics.draw(spritebatch)
end

function updateParticles(dt)
--note the reversed order to avoid errors when using table.remove
for i = #particles, 1, -1 do
local p = particles[i]

p.x = p.x + p.ax * dt
p.y = p.y + p.ay * dt
p.ay = p.ay + dt

table.remove(particles, i)
end
end
end
``````

### Re: Independent Particle Colors

Posted: Thu Nov 07, 2019 9:53 am
Sorry for late reply.. aha. Something outside of a particle system.

Code: Select all

``````-- Create some confetti
local ConfettiList = {}
for i=1, #ConfettiList do
-- Draw confetti with spritebatches here
end
``````

Just saw Luke100000's post. 100% use his example