我正在尝试将9个声音文件加载到数组中,这样当我的精灵执行动画时,它们可以以特定值(1到9)播放。
到目前为止,我已经使用AndEngine SoundFactory创建了声音。
this.mGrondin1 = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), getApplicationContext(), "Earn my pay.wav");
this.mGrondin2 = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), getApplicationContext(), "Spaghetti code.wav");
this.mGrondin3 = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), getApplicationContext(), "Business major.wav");
this.mGrondin4 = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), getApplicationContext(), "Microsoft code.wav");
this.mGrondin5 = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), getApplicationContext(), "How I would do it.wav");
this.mGrondin6 = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), getApplicationContext(), "Not efficient.wav");
this.mGrondin7 = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), getApplicationContext(), "Flying Blind.wav");
this.mGrondin8 = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), getApplicationContext(), "Minus two.wav");
this.mGrondin9 = SoundFactory.createSoundFromAsset(this.mEngine.getSoundManager(), getApplicationContext(), "Turn off your life.wav");
现在我想将它们全部加载到一个易于访问的形式,如数组。我怎么能这样做?
更新 我没有创建一大堆声音并尝试将它们加载到数组中,而是简单地创建了一系列声音并将所有文件加载到其中。
for (int i = 0; i < arSounds.length; i++) {
this.arSounds[i] = SoundFactory.createSoundFromAsset(
this.mEngine.getSoundManager(),
getApplicationContext(), "Grondin" + (i + 1) + ".wav");
}
将它们全部加载到arSounds数组中。然后我做了随机游戏
Random gen;
arSounds[gen.nextInt(8)].play();