Cocos2d-x iOS CocosDenshion Sound Player - 定时播放 MS

Cocos2d-x iOS CocosDenshion Sound Player - Play at certain time MS

使用Cocos2d 3.

我正在尝试研究如何在加载的效果/声音中从特定时间/毫秒开始播放声音或音乐。

本质上是 cocosDenshion 的 setTime 方法 class?

有人有什么想法吗?或者这是我可以贡献的东西?

你可以这样做:

auto sae = CocosDenshion::SimpleAudioEngine::getInstance();

someSprite->runAction(Sequence::createWithTwoActions(DelayTime::create(time), CallFunc::create([&](){ sae->playEffect("mySound.wav"); })));

Wav 应该比其他扩展具有最小的延迟。

您也可以预加载它:

sae->preloadEffect("mySound.wav");

如果您需要高精度,仍然不能保证您会在完美的时机使用它,但这是硬件问题。

你可以像

一样在某个时间后调用调度

代码

  this->scheduleOnce(schedule_selector(HelloWorld::sound_method), 0.5);
void Helloworld::sound_method(float ty)
{     CocosDenshion::SimpleAudioEngine::getInstance( )->playEffect("Byuuton_yap.mp3");   }

这里0.5是时间,sound_method0.5秒后调用。 我希望,这个答案对某人有所帮助