SKEmitterNodeクラスを使ってエフェクトを操作してみます。
numParticlesToEmitプロパティに値を設定すると、指定した値の数だけパーティクルを生成した後、SKEmitterNodeオブジェクトは消滅します。
また、particleScaleプロパティなどを指定することにより、プログラムからも設定を変更できます。
HelloScene.m
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
SKEmitterNode *smoke = [self newSmokeEmitter];
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
smoke.position = location;
smoke.particleBirthRate = 5;
smoke.numParticlesToEmit = 100;
smoke.particleScale = 0.3;
smoke.particleScaleRange = 0.2;
smoke.particleScaleSpeed = -0.1;
[self addChild:smoke];
}
Keyframe Sequence を使って、Particle Emitter Editor では指定できない動きを作ることもできます。
次の例では、scale を lifetime*0.0秒後に0.2 ⇒ lifetime*0.25秒後に0.7 ⇒ lifetime*0.75秒後に0.1と変化させています。
HelloScene.m
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
SKEmitterNode *smoke = [self newSmokeEmitter];
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
smoke.position = location;
smoke.particleBirthRate = 5;
smoke.numParticlesToEmit = 100;
SKKeyframeSequence *scaleSequence = [[SKKeyframeSequence alloc] initWithKeyframeValues:@[@0.2, @0.7, @0.1] times:@[@0.0, @0.25, @0.75]];
smoke.particleScaleSequence = scaleSequence;
[self addChild:smoke];
}
今回はここまで。