CAEmitterCell不尊重持续时间值 [英] CAEmitterCell does not respect the duration value

查看:129
本文介绍了CAEmitterCell不尊重持续时间值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个发射器,我想在2秒后结束,但我不能让它停止运行!

I have an emitter that I want to end after 2 seconds, but I can't get it to stop running!

我的代码如下:

// Emitter Layer
    //
    emitter = [CAEmitterLayer layer];
    emitter.emitterSize = CGSizeMake(20, 20);
    emitter.renderMode = @"additive";
    emitter.emitterMode = @"points";
    emitter.emitterShape = @"rectangle";
    emitter.emitterPosition = CGPointMake(310, 230);
    //emitter.duration = 2; // setting duration on the emitterLayer prevents anything from firing it seems

// Emitter Cells
    //

    // 'New Emitter' cell configuration
    newEmitter = [CAEmitterCell emitterCell];
    newEmitter.scaleSpeed = 7;
    newEmitter.lifetime = 2.481715;
    //newEmitter.duration = 2; // I would expect this to stop the emitter after 2 seconds, but it doesn't!
    newEmitter.velocity = 332.3636968085106;
    newEmitter.contents = newemitterImg;
    newEmitter.name = @"New Emitter";
newEmitter.scaleRange = 4.178236607142859;
    newEmitter.lifetimeRange = 1.6;
    newEmitter.greenRange = -2.775558e-17;
    newEmitter.birthRate = 40;
    newEmitter.emissionRange = -6.283185306666667;
    newEmitter.scale = 0;

    // Emitter Cell Chains
    //

    emitter.emitterCells = [NSArray arrayWithObjects:newEmitter, nil];

尽管作为iOS的一部分约2年,但似乎很少有关于此的信息!

There seems to be very little information on this available despite being a part of iOS for about 2 years!

推荐答案

您可以使用计时器和停止发射器生成新粒子的方法...

You can do this with a timer, and a method to stop the emitter generating new particles...

在现有代码的末尾添加:

At the end of your existing code add:

    [newEmitter setName:@"newEmitter"];
    [NSTimer scheduledTimerWithTimeInterval:2.0
                                     target:self
                                   selector:@selector(stopEmitter:)
                                   userInfo:nil
                                    repeats:NO];

然后制作一个stopEmitter:方法......

Then make a stopEmitter: method…

    - (void) stopEmitter:(NSTimer*)timer
    {
        [emitter setValue:@0
               forKeyPath:@"emitterCells.newEmitter.birthRate"];
    }

这篇关于CAEmitterCell不尊重持续时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆