CAEmitterLayer emits random unwanted particles on touch events

后端 未结 3 1379
灰色年华
灰色年华 2021-02-01 14:01

I\'m trying to set up a CAEmitterLayer to make a confetti effect, and I\'ve run into two issues:

  1. Whenever I set the birthRate on my cell
3条回答
  •  隐瞒了意图╮
    2021-02-01 15:04

    Could it be that you aren't checking to see if the particle is emitting like in the Wenderlich example Artur Ozieranski posted? I'm not seeing the doubling as long as the check is in place.

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        [fireView setEmitterPositionFromTouch: [touches anyObject]];
        [fireView setIsEmitting:YES];
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        [fireView setIsEmitting:NO];
    }
    
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
        [fireView setIsEmitting:NO];
    }
    -(void)setIsEmitting:(BOOL)isEmitting
    {
        //turn on/off the emitting of particles
        [fireEmitter setValue:[NSNumber numberWithInt:isEmitting?200:0] forKeyPath:@"emitterCells.fire.birthRate"];
    }
    

提交回复
热议问题