等到加载资产

时间:2019-07-28 02:55:34

标签: javascript reactjs redux tone.js

我在这里https://maliyshock.github.io/simon-says/有一个应用程序 对于此应用,我正在使用此库https://tonejs.github.io 我需要确保所有声音都已成功下载。在运行应用程序之前。

在我看来,在将来的更新中,它将成为吉他英雄,但步伐敏捷。 :D 我将创建具有不同声音,节奏和持续时间的音乐短语。其主要特征是可重播性。因为每首歌都是从词组中产生的。

在redux / react堆栈中,我们应该通过分派操作来更新应用程序的状态,以告诉reducer该怎么做。

问题是,我需要在游戏开始之前下载所有声音。我看到的唯一方法是将其制作在减速器内部。但这对我来说似乎是错误的。

const initialWordsState = {
    dictionary: [
        {
            ALFA: {
                color: {
                    name: 'blue',
                    value: BLUE
                },
                sound: new Tone.Player({ "url": alfa_sound, 'onload': ()=>{} }).toMaster(),
                active: false
            }
        },
        {
            OMEGA: {
                color: {
                    name: 'orange',
                    value: ORANGE
                },
                sound: new Tone.Player({ "url": omega_sound, 'onload': ()=>{} }).toMaster(),
                active: false
            },
        },
        {
            BETHA: {
                color: {
                    name: 'red',
                    value: RED
                },
                sound: new Tone.Player({ "url": betha_sound, 'onload': ()=>{} }).toMaster(),
                active: false
            },
        },
        {
            THETHA: {
                color: {
                    name: 'green',
                    value: GREEN
                },
                sound: new Tone.Player({ "url": thetha_sound, 'onload': ()=>{} }).toMaster(),
                active: false
            }
        }
    ]
};

如您所见,每个按钮都有声音。将来,每个按钮都会在短语和声音持续时间方面有多种声音。

我不确定该怎么做。我唯一想到的就是使用onload中的Tone.player回调来更新商店,并在所有声音下载完毕后用勾号勾选它。如果所有文件都已下载-请显示正确的屏幕。 但是在我看来,那样做是错误的。

0 个答案:

没有答案