how change color particles?

I need to emit particles of different colors but when I run these particles do not change color. in particle properties definition, I wrote this:

imagePath = “star.png”,
imageWidth = 20,
imageHeight = 20,
velocityStart = 150,
directionVariation = 360,
autoRotation = false,
colorStart = ({30,15,40}), colorChange =({-50,50,0}), alphaStart = 0.9,
alphaVariation = 0.1,
fadeOutSpeed = -1.0,
fadeOutDelay = 1000,
weight = 1,–0.2,
killOutsideScreen = true,
lifeTime = 1000,
–blendMode = “add”
thank you!!! [import]uid: 59020 topic_id: 15802 reply_id: 315802[/import]

Particles of a certain particle type are always created with the color currently set with the particle type. So if you want to create particles in different, randomly colors, you need to change a particle type’s color frequently. You can do this within an enterFrame listener function, for example:

[lua]function MyEnterFrameListener( event )

– RANDOMLY CHANGE PARTICLE TYPE’S COLOR
local red = math.random()*255
local green = math.random()*255
local blue = math.random()*255
Particles.SetParticleProperty(“MyParticleType”, “colorStart” , {red, green, blue})
end[/lua]
BTW, you placed round brackets around the color arrays in your code above. The correct syntax, however, is:

[lua]colorStart = {30,15,40}, colorChange ={-50,50,0},

May I ask :

Why do use use math.random()\*255 instead of math.random(255) ?
[import]uid: 9328 topic_id: 15802 reply_id: 67905[/import]

It’s basically the same, but you’re right, using math.random(255) may be better in this case since it returns integer values only. [import]uid: 10504 topic_id: 15802 reply_id: 68151[/import]

Oh. I thought it was for performance/optimization.

thx for your answer. [import]uid: 9328 topic_id: 15802 reply_id: 68154[/import]

hi! I try with this code, no color change but…

the console shows me

-> Particles.SetParticleProperty (): SET FairDust.colorStart (table).
any idea?.. thank you:) [import]uid: 59020 topic_id: 15802 reply_id: 68180[/import]

You need to install one of the latest Corona daily builds to have access to this feature since it is only supported by the pro version of Corona yet.

If you did so and still can’t get it to work, please some more code (or email it to us), so we can look through it. [import]uid: 10504 topic_id: 15802 reply_id: 68188[/import]

Hello,

I am also trying to get different color particles (randomly selected at the beginning of each game( not on the fly)

I tried using “tint” like this:

[lua]-- EFFECT LIBRARIES CLEANUP FUNCTION.
Images[1] = display.newImageRect(particleImagesPath…“smoke1_light_dark.png”,64,64
Images[1]:setFillColor( mRand(1,255), mRand(1,255), mRand(1,255) )
…[/lua]

And the colorStart feature:

[lua]Particles.CreateParticleType (“FireballSlow”,
{
imagePath = particleImagesPath…“fireball_medium.png”,
imageWidth = 64,
imageHeight = 64,
directionVariation = 360,

lifeTime = 1000,
blendMode = “add”,
colorStart = {red, green, blue}
} )[/lua]

But no luck so far. No error message no different color either. I am using the latest trial version (704) and would that the problem why I do not see any color changes?

I guess i am trying to do is having the explosion have different tint each time the game is played (but not necessarily on the fly color changes since i think it would slow down the game…just a guess)

Thanks a lot for any pointers.

Mo [import]uid: 49236 topic_id: 15802 reply_id: 80091[/import]

Mo, please have a look at the included sample “Sample_Color_Change” which does and explains exactly what you are looking for.

In the effect library, Images[] is just a table to hold preloaded copies of the images used (to prevent hick-ups), there is no need to colorize these images (as you do in your first code snippet), so you can ignore it.

The colorStart property sets the current color of the particles, which will stay the same as long as you change it again. So your second code applies a random color to this particle type, but the color won’t change unless you change this property again. If you want to have explosions in different colors each time, you have to change this property using SetParticleProperty() each time before triggering the explosion. [import]uid: 10504 topic_id: 15802 reply_id: 80141[/import]

Thanks so much for the info. I was using an older version of PC and did not see all the new effects. WOW, those are fantastic effects.

I will look at the example and report.

Appreciate the great support and your great library. Having a blast with it!

Mo [import]uid: 49236 topic_id: 15802 reply_id: 80147[/import]

Indeed, SetParticleProperty() did it. Thank you! Now the explosions are spectacular with those different colors scheme at each game start.

Thank you again.

Mo [import]uid: 49236 topic_id: 15802 reply_id: 80205[/import]