1

In the rhythm app I'm creating, I've set up a single particle emitter for each key that's played correctly.

enter image description here

Here's the code that triggers this:

-(void) enableEmitterForNoteValue:(int)noteValue WithPercentage:(double)percentage {
    int index = noteValue - 36;
    SKEmitterNode *emitter = [_emitters objectAtIndex:index];


    emitter.particleColorSequence = nil;
    emitter.particleColorBlendFactor = 1.0;
    if (percentage == kNotePerfectHitPercentage)
        [emitter setParticleColor:[NSColor whiteColor]];
    else if (percentage == kNoteOkayHitPercentage || percentage == kNoteEarlyHitPercentage)
        [emitter setParticleColor:[NSColor yellowColor]];
    else if (percentage == kNoteLateHitPercentage)
        [emitter setParticleColor:[NSColor orangeColor]];

    [emitter resetSimulation];
    [emitter setParticleBirthRate:200];
}

Problem: When notes at the same pitch (played with the same key) occur in rapid succession, the particles that are emitted are reset because I'm called resetSimulation:. If I don't call resetSimulation:, then the particles will only show up once. Is there a way to get around this? Here's an example of notes that come in quick succession below.

enter image description here

02fentym
  • 1,762
  • 2
  • 16
  • 29
  • I am not understanding your question, you want to reset the particles without resetting the particles? – Knight0fDragon Jul 02 '17 at 01:41
  • I need a way to handle the emitters so that they finish emitting all of their particles for each correct note played. Because of the `resetSimulation:` method, the emitter is being cut off. Does this make sense? – 02fentym Jul 02 '17 at 01:44
  • OK I think I understand, you only have 1 emitter per note – Knight0fDragon Jul 02 '17 at 01:45
  • Exactly. Originally, I created an emitter for every single time a note was played correctly. I would create the emitter, add it to the scene and then remove it via an SKAction, but it causes my MIDI handler to break for some reason and I don't know how to debug it because things are handled on different threads and there are timing issues, etc. – 02fentym Jul 02 '17 at 01:47
  • I am thinking how I want to write your answer, but the basic summary is you do not want to be doing what you are doing. You want to create a pool of emitters, and keep grabbing from the pool and altering the color based on the note – Knight0fDragon Jul 02 '17 at 01:48
  • Ok, can you elaborate a bit more on the problem with the way I'm approaching this situation and why your solution is better? Thanks for the quick response :) – 02fentym Jul 02 '17 at 01:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/148147/discussion-between-knight0fdragon-and-02fentym). – Knight0fDragon Jul 02 '17 at 01:50

0 Answers0