Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to change the color of the particles emitted by my SKEmitterNode from WITHIN the code

I have an app where the user can edit an emitter node and take a screenshot to the photo library. In the settings where they can change stuff like the birthrate, angle, ect. I allow them to change the color of the emitter node.

I am using:

node.particleColor = [SKColor redColor];

and it isn't changing the color of the particles.

However when I added NSLog statements to it and asked it what node.particleColor was it returned 1 0 0 1, which is what I was expecting but the node never changes color.

Any ideas as to what I can do to change its color?

like image 530
user3473834 Avatar asked Mar 28 '14 18:03

user3473834


1 Answers

Hey i think i just figured out this problem. Not sure if your code is different however.

For me i have a SKEmitterNode created like this

SKEmitterNode *explosion = [NSKeyedUnarchiver
                                        unarchiveObjectWithFile:[[NSBundle mainBundle]
                                        pathForResource:@"Explosion" ofType:@"sks"]];

then to change its color i do this

explosion.particleColor = [SKColor redColor];

then in i set the blend factor to 1

explosion.particleColorBlendFactor = 1.0;

and finally i turn the color sequence to nil (this was the tricky part)

explosion.particleColorSequence = nil;

By turning the color sequence to nil, it no longer ignores the particle color. Not sure why it initially wasn't set to nil like the reference says, but this is what fixed it for me. Hope this helps!

like image 162
Chris Brasino Avatar answered Oct 09 '22 23:10

Chris Brasino