Independent Particle Colors

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Luke100000
Party member
Posts: 231
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Re: Independent Particle Colors

Post by Luke100000 » 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,
		lifetime = math.random()+1.0,
	})
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
		p.lifetime = p.lifetime - dt
		
		if p.lifetime < 0 then
			table.remove(particles, i)
		end
	end
end

User avatar
kicknbritt
Citizen
Posts: 59
Joined: Sat May 30, 2015 2:15 am
Location: Chicago, IL/Anchorage,AK

Re: Independent Particle Colors

Post by kicknbritt » 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
[Edit]
Just saw Luke100000's post. 100% use his example
"I AM THE ARBITER!!!" *Pulls out Energy sword and kills everything*

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests