2

I am working on a game that has coins, power ups, and death sounds. The usual for a game. My sound engineer is telling me that in order to make it sound good, I need to have a 300ms delay between all sounds so that they do not play on top of each other and make the sound louder.

E.g., if you pickup multiple coins within that 300ms I don't want to play the sound for all of them.

Here is how I am playing a randomized death sound. But how do I add a delay?

int random = rand() % 4;

switch (random) {
    case 0:
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect( enemyDeathSoundName );
        break;
    case 1:
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect( enemyDeathSoundName2 );
        break;
    case 2:
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect( enemyDeathSoundName3 );
        break;
    case 3:
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect( enemyDeathSoundName4 );
        break;

    default:
        break;
}

Does anyone have ideas on how this is possible?

Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412

2 Answers2

0

use some existing node, and play an delaytime action. like

node->runAction(Sequence.create(DelayTime.create(0.5), CallFunc.create(playSound)));

then play sound in function playSound.

it's a trick, if you don't have a better choice

yangguang1029
  • 1,813
  • 14
  • 16
0

You can add in an array the events (as actions) and run the action as a sequence for example you add the event for one enemy in the array and if you killed 3 enemies add multiple actions in an array with the DelayTime and run in a Sequence.

You could check how to add an array (vector) of actions here:

http://www.cocos2d-x.org/reference/native-cpp/V3.0rc1/d7/d30/classcocos2d_1_1_sequence.html