0

HTML5とJSでサイコロを使ったゲームを作っています。次に、サイコロの画像をプリロードする必要があります。preloadJS ライブラリを使用しています。だから私の質問は、サイコロごとに同じコードを書かずに 2 つ以上のマニフェストをプリロードするにはどうすればよいですか? 私の例を見てください。

私のマニフェスト ファイルは、dice_twos、dice_threes、dice_fours、dice_fives、dice_sixes です。 * 1 つのサイコロに対して 50 枚の画像があります*

var n=0;
var diceRegX = 45;//X registration point for dice 
var diceRegY = 45;//Y registration point for dice 

for(var i=0; i<50;i++){
    dice_twos.push({ src: "Assets/DiceImages/ONE_Main." + i + ".png", id: "dice" + i, reelImg: false });
    dice_threes.push({ src: "Assets/DiceImages/ONE_Main." + i + ".png", id: "dice" + i, reelImg: false });
    dice_fours.push({ src: "Assets/DiceImages/ONE_Main." + i + ".png", id: "dice" + i, reelImg: false });
    dice_fives.push({ src: "Assets/DiceImages/ONE_Main." + i + ".png", id: "dice" + i, reelImg: false });
    dice_sixes.push({ src: "Assets/DiceImages/ONE_Main." + i + ".png", id: "dice" + i, reelImg: false });
}
preload = new createjs.PreloadJS();
preload.onFileLoad = handleFileLoad;
preload.onProgress = handleOverallProgress;
preload.onFileProgress = handleFileProgress;
preload.onError = handleFileError;

function stop() {
    if (preload != null) {
        preload.close();
    }
}

function loadAll() {
    while (dice_twos.length > 0) {
        loadAnother();
    }
}

function loadAnother() {
    var item1 = dice_twos.shift();
    handleFileLoad(item1);
}

// File complete handler 
function handleFileLoad(event1) {
    dice_1[n] = new createjs.Bitmap(event1.src);
    dice_1[n].name = ('dice' + (n + 1));
    dice_1[n].regX = (diceRegX - 5);
    dice_1[n].regY = (diceRegY - 5);
    dice_1[n].x = (canvas.width + 80);
    dice_1[n].y = (canvas.height / 2);
    n++;
}

handleFileLoad 関数に別の引数を渡そうとしましたが、うまくいかないようです。どんな助けでも大歓迎です。ありがとう

4

1 に答える 1

2

こんにちは皆さん、これが私が必要とする解決策です。これが誰かの助けになることを願っています...乾杯

var dice_twos = new Array();
        var dice_threes = new Array();
        var dice_fours = new Array();
        var dice_fives = new Array();
        var dice_sixes = new Array();   
        var dice_1 = new Array();
        var dice_2 = new Array();
        var dice_3 = new Array();
        var dice_4 = new Array();
        var dice_5 = new Array();
        var dice_6 = new Array();
        var i = 0;
        var n = 0;
        var item1;
        var item2;
        var item3;
        var item4;
        var item5;
        var item6;

     for (var i = 1; i <= 50; i++) {
                        dice_twos.push({ src: "Assets/DiceImages/TWO_Main." + i + ".png", id: "dice" + i, reelImg: false });
                        dice_threes.push({ src: "Assets/DiceImages/THREE_Main." + i + ".png", id: "dice" + i, reelImg: false });
                        dice_fours.push({ src: "Assets/DiceImages/FOUR_Main." + i + ".png", id: "dice" + i, reelImg: false });
                        dice_fives.push({ src: "Assets/DiceImages/FIVE_Main." + i + ".png", id: "dice" + i, reelImg: false });
                        dice_sixes.push({ src: "Assets/DiceImages/SIX_Main." + i + ".png", id: "dice" + i, reelImg: false });
                    }
            }
            // Create a preloader. There is no manfest added to it up-front, we will add items on-demand.
            preload = new createjs.PreloadJS();
            preload.onFileLoad = handleFileLoad;
            preload.setMaxConnections(5);
            loadAll();
        }

        function stop() {
            if (preload != null) { preload.close(); alert("preloader closed..."); }
        }
        function loadAll() {
            while (dice_ones.length > 0) {
                loadAnother();
            }
        }
        function loadAnother() {
            // Get the next manifest item, and load it
            item1 = dice_ones.shift();
            item2 = dice_twos.shift();
            item3 = dice_threes.shift();
            item4 = dice_fours.shift();
            item5 = dice_fives.shift();
            item6 = dice_sixes.shift();
            handleFileLoad(item1);

        }
        // File complete handler
        function handleFileLoad(event1) {
            dice_1[n] = new createjs.Bitmap(event1.src);
            dice_1[n].name = ('dice' + (n + 1));
            dice_1[n].regX = (diceRegX - 5);
            dice_1[n].regY = (diceRegY - 5);
            dice_1[n].x = (canvas.width + 80);
            dice_1[n].y = (canvas.height / 2);
            dice_1[n].in_holder = (-1);

            dice_2[n] = new createjs.Bitmap(item2.src);
            dice_2[n].name = ('dice' + (n + 1));
            dice_2[n].regX = (diceRegX - 5);
            dice_2[n].regY = (diceRegY - 5);
            dice_2[n].x = (canvas.width + 80);
            dice_2[n].y = (canvas.height / 2);
            dice_2[n].in_holder = (-1);

            dice_3[n] = new createjs.Bitmap(item3.src);
            dice_3[n].name = ('dice' + (n + 1));
            dice_3[n].regX = (diceRegX - 5);
            dice_3[n].regY = (diceRegY - 5);
            dice_3[n].x = (canvas.width + 80);
            dice_3[n].y = (canvas.height / 2);
            dice_3[n].in_holder = (-1);

            dice_4[n] = new createjs.Bitmap(item4.src);
            dice_4[n].name = ('dice' + (n + 1));
            dice_4[n].regX = (diceRegX - 5);
            dice_4[n].regY = (diceRegY - 5);
            dice_4[n].x = (canvas.width + 80);
            dice_4[n].y = (canvas.height / 2);
            dice_4[n].in_holder = (-1);

            dice_5[n] = new createjs.Bitmap(item5.src);
            dice_5[n].name = ('dice' + (n + 1));
            dice_5[n].regX = (diceRegX - 5);
            dice_5[n].regY = (diceRegY - 5);
            dice_5[n].x = (canvas.width + 80);
            dice_5[n].y = (canvas.height / 2);
            dice_5[n].in_holder = (-1);

            dice_6[n] = new createjs.Bitmap(item6.src);
            dice_6[n].name = ('dice' + (n + 1));
            dice_6[n].regX = (diceRegX - 5);
            dice_6[n].regY = (diceRegY - 5);
            dice_6[n].x = (canvas.width + 80);
            dice_6[n].y = (canvas.height / 2);
            dice_6[n].in_holder = (-1);
            n++;                
        }
于 2012-12-25T12:10:46.523 に答える