Colors are taken from Renderer.color_palette texture (name is from my head, may be different a bit), this is a 2D texture. You can look it up or change it.
But what algorithm is used to determine the exact colour for a particular particle? I guess the particle's lifetime is part of the algorithm? Similarly, I would guess that the particle.color applies too?
Alternatively, can we please have a function to return a specific particle's color?
I want particles to emit a light corresponding with their colour.
// manually calculate color of palette based particle (particles with 'palette' set to true)
Flt ParticleOpacity(Flt particle_life, Flt particle_life_max, Bool particles_smooth_fade); // calculate opacity of a single particle by specifying its current life 'Particle.life', maximum life 'Particle.life_max' and if smooth fade 'Particles.smooth_fade' is enabled, this opacity can be used for function below 'ParticleColor'
Color ParticleColor (Flt particle_opacity, C Color &particles_color, C Image &palette_image); // calculate color of a single particle by specifying its opacity (can be obtained using 'ParticleOpacity' function), color of particles 'Particles.color' and palette image used by the particles (depending on 'Particles.paletteIndex' it can be 'Renderer.color_palette' or 'Renderer.color_palette1'), this 'ParticleColor' function requires locking for reading the palette image and accessing its pixels, since 'Renderer.color_palette' images are 2D textures, locking them for every function call may not be efficient, it is suggested to copy those images to other image in IMAGE_SOFT mode at application startup, and then pass the software versions of the images to this function (locking and accessing software images has no performance penalty)
I'm still having some difficulty though. I'm editing the EditObjectParticles function in the editor. Using the code above gives me the following function:
And produces the attached image.
The locations of the particles are correct, and the transition appears to occur correctly. However, the colour is still wrong. In particular, the particles start white and change to yellow. I don't believe that any palette does that.
Colour is (137, 0, 0, 0)
I'm at a bit of a loose end here. I have absolutely no idea why it isn't working and I've been fiddling with it for hours :(
(This post was last modified: 05-12-2013 07:19 PM by mystara.)
And using that inside the ParticleColor() function. This produces exactly the same effect as above.
I've tried varying both the ParticleOpacity() and Color values, but I still don't get the right output.
It seems that if the above code is executed inside a drawPalette() function, it produces the above effect. But if the above code is executed inside the Draw() function, it works correctly....?
(This post was last modified: 05-13-2013 10:21 PM by mystara.)
So which method of ObjClass should I override, rather than using the Draw() function?
Or do I need to code my Draw() function to specifically call a method inside my extended ObjClass object?
I still haven't really got the hang of the different functions and when they're called :/
It turns out that it was working correctly. It's just that the white light produced by a small number of particles was washing out the other coloured particles.