【发布时间】:2016-04-29 16:45:20
【问题描述】:
我正在尝试在游戏菜单中播放随机声音,实际上是鸟儿的叫声。 所以有很多鸟的声音,但我希望它们是随机的。
我之前使用schedule 完成了此操作,如下所示:
this->schedule(schedule_selector(HelloWorld::birdsound),3.2);
地点:
void HelloWorld::birdsound(){
int soundnum=arc4random()%9+1;
switch (soundnum) {
case 1:
appdelegate->bird1();
break;
case 2:
appdelegate->bird2();
break;
.
.
.
case 9:
appdelegate->bird9();
break;
default:
break;
}
}
因此,播放随机声音,例如bird1():
void AppDelegate::bird1(){
CocosDenshion::SimpleAudioEngine::sharedEngine()->stopAllEffects();
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("bird1.mp3");
}
如何在 Spritekit/swift 中实现类似的东西,我可以在其中以随机顺序拥有X 数量的声音文件(或鸟叫声),中间有一个小间隙(或等待)?这可以用SKActions 完成吗?
【问题讨论】:
标签: swift sprite-kit scheduled-tasks skaction