Particle System :setColors Has No Effect on Sprite [Solved]

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.
Post Reply
User avatar
Azzla
Prole
Posts: 39
Joined: Sun Mar 29, 2020 2:23 am

Particle System :setColors Has No Effect on Sprite [Solved]

Post by Azzla »

Hi, I'm trying to figure out how the :setColors method for particle systems works. The documentation seems to imply this method will override the colors from the initial sprite ("apply them to the sprite" ?) and use the specified values instead, but I've not seen any effect.

My game is a pixel art game, and so almost all my pSystems use single-pixel sprites with the different colors in my palette. It feels wasteful and unnecessary to create a new particle system, with a new single-pixel asset, for every color variation when they have the exact same dimensions. I'm hoping there's a more elegant way to do it.

Here is my code:

Code: Select all

function spawnBulletParticles(pSys, numOfParticles, isDamageUp)
  local direction = player_angle() - math.pi/2 - math.pi/8
  local increment = math.pi/4 / numOfParticles
  
  if isDamageUp then
    print('damage is increased')
    pSys:setColors(rgb(183), rgb(231), rgb(246), 1)
  end
  
  for i = 1, numOfParticles do
    pSys:setDirection(direction)
    pSys:emit(1)
    direction = direction + increment
  end
end
rgb() is just a utility function that divides the value by 255 so I can work with colors in the rgb space.

The sprite for this pSystem is blue, and I'm trying to change it to red while a damage powerup is active. Print statement confirms that :setColors is running and I'm not getting errors, but the emitted particles remain blue. Is there a way achieve what I'm looking for? And what is the expected functionality of :setColors?
Last edited by Azzla on Wed May 11, 2022 7:09 pm, edited 2 times in total.
libraries: Stalkpile
electronic music stuff: https://soundcloud.com/azzlamusic
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Particle System :setColors Has No Effect on Sprite

Post by ReFreezed »

The colors of the pixels in the texture are multiplied with the colors set by :setColors() (and love.graphics.setColor). The texture has to be grayscale if you want to control the color with :setColors() exclusively. Technically you can change the color in any way you want with custom shaders, but I'm guessing that's overkill for what you want here. Note that :setColors() immediately affects the colors of all emitted particles in the particle system - not just a single particle - unlike :setDirection() which only affects newly emitted particles.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
Azzla
Prole
Posts: 39
Joined: Sun Mar 29, 2020 2:23 am

Re: Particle System :setColors Has No Effect on Sprite

Post by Azzla »

ReFreezed wrote: Wed May 11, 2022 2:01 pm The colors of the pixels in the texture are multiplied with the colors set by :setColors() (and love.graphics.setColor). The texture has to be grayscale if you want to control the color with :setColors() exclusively. Technically you can change the color in any way you want with custom shaders, but I'm guessing that's overkill for what you want here. Note that :setColors() immediately affects the colors of all emitted particles in the particle system - not just a single particle - unlike :setDirection() which only affects newly emitted particles.
Ah, this helped me figure out why my sprite wasn't affected - I was using my blue rgb values instead of my red ones, thus the lack of apparent effect. When using the correct red values, the sprite is multiplied to murky black color, and when I use a pure white sprite, it has the effect I was looking for. Thanks! :awesome:
libraries: Stalkpile
electronic music stuff: https://soundcloud.com/azzlamusic
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests