1

我正在尝试将 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();
4

0 回答 0