LoginSignup
1
1

More than 5 years have passed since last update.

SpriteKit入門 -22-

Posted at

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];
}

spritekit_22_01.png

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];
}

spritekit_22_02.png

今回はここまで。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1