I am making a game with dices with HTML 5 and JS. Now I need to preload the dice images. I am using preloadJS library. So my question is how can i preload two or more manifests without writing the same code for every dice? Please see my example.
My manifest files are: dice_twos, dice_threes, dice_fours, dice_fives, dice_sixes.
*I have 50 images for one dice*
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++;
}
I was trying to pass another argument to handleFileLoad function but doesn’t seems to work. Any help will be appreciated. Thanks
Hi guys Here is the solution of that what I need. I hope that this will help someone… Cheers