我试图在游戏菜单中播放随机声音,它实际上是鸟儿在吱吱作响。 所以有很多鸟的声音,但我希望他们是随机的。在SpriteKit中安排音频 - Swift
我以前做过这个使用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
完成吗?