1

How can I create slow motion effect for all currently playig sounds and music in my game? I'm using cocos2d v2.1 and ObjectAL.

I can set timescale for scheduler, but how I can do this for sound together?

KAMIKAZE
  • 420
  • 6
  • 27

1 Answers1

1

Keep references to the CDSoundSource of each sound and bg output:

CDSoundSource *bgMusic = [[SimpleAudioEngine sharedEngine]soundSourceForFile:@"mysong1.mp3"];

[mySoundArray addObject:bgMusic];

Then create a method to ramp down the pitch of all references at a scheduled interval:

-(void)testUpdate:(ccTime)dt
{
    float myRampVal = 0.05f;
    float finalPitch = 0.5f;

    for(CDSoundSource *sound in mySoundArray)
    {
        sound.pitch -= myRampVal;

        if(sound.pitch < finalPitch)
        {
             sound.pitch = finalPitch;
        }
    }
}

Schedule by calling the following when you want to lower the pitch:

[self schedule:@selector(audioDownRamp:) interval:0.1f];
Lorenzo Linarducci
  • 541
  • 1
  • 4
  • 8
  • I thought about such solution, but it's also need to be works using **ObjectAL** and not simpleaudio. The problem of solution you provide is that when a lot of short sounds currently playing or maybe not.. I don't know, because they are created dynamically. I'm using such method to play sound" `[[OALSimpleAudio sharedInstance] playEffect : effect volume: gain pitch: 1.0f pan: pan loop: NO];` – KAMIKAZE Mar 20 '14 at 18:37