Reputation: 3233
Using Cocos2d 3.
I am trying to work out how it is possible to play a sound or music from a certain time / millisecond within the loaded effect / sound.
Essentially a setTime method for the cocosDenshion class?
Anyone have any ideas? Or is this something I could contribute?
Upvotes: 0
Views: 217
Reputation: 363
You can call the schedular after a certain a time like
this->scheduleOnce(schedule_selector(HelloWorld::sound_method), 0.5);
void Helloworld::sound_method(float ty)
{ CocosDenshion::SimpleAudioEngine::getInstance( )->playEffect("Byuuton_yap.mp3"); }
here 0.5 is time ,sound_method call after 0.5 second. i hope,this answer help someone
Upvotes: 2
Reputation: 7521
You can do this:
auto sae = CocosDenshion::SimpleAudioEngine::getInstance();
someSprite->runAction(Sequence::createWithTwoActions(DelayTime::create(time), CallFunc::create([&](){ sae->playEffect("mySound.wav"); })));
Wav should have smallest delay than other extension.
You can also preload it:
sae->preloadEffect("mySound.wav");
Still it's no guaranteed you will here it in perfect timing if you need high precision, but that's a hardware problem.
Upvotes: 1