crowds/js/slideshow/Preloader.js

82 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-04-16 15:44:14 +00:00
// Load just enough for the splash screen
subscribe("prepreload", function(){
Preload([
// For the Sim
2018-04-16 19:14:08 +00:00
{id:"button_large", image:"sprites/button_large.png"},
{id:"line", image:"sprites/line.png"},
{id:"peeps", image:"sprites/peeps.png"},
{id:"pencil", image:"sprites/pencil.png"},
2018-04-16 15:44:14 +00:00
],function(progress){
console.log("Pre-Preloader: "+progress);
if(progress==1){
var pre_preloader = $("#pre_preloader");
pre_preloader.parentNode.removeChild(pre_preloader);
2018-04-16 19:14:08 +00:00
slideshow.gotoChapter("Networks-Threshold");
2018-04-16 15:44:14 +00:00
publish("preload");
}
});
});
// Load the rest of it
window.PRELOAD_PROGRESS = 0;
subscribe("preload", function(){
Preload([
// Music
2018-04-16 19:14:08 +00:00
{id:"bg_music", audio:"audio/bg_music.mp3"},
2018-04-16 15:44:14 +00:00
// For the slides
2018-04-16 19:14:08 +00:00
{id:"sandbox_tools", image:"sprites/sandbox_tools.png"},
{id:"scratch", image:"sprites/scratch.png"},
{id:"tutorial_connect", image:"sprites/tutorial_connect.png"},
{id:"tutorial_disconnect", image:"sprites/tutorial_disconnect.png"},
2018-04-16 15:44:14 +00:00
],function(progress){
console.log("Preloader: "+progress);
window.PRELOAD_PROGRESS = progress;
});
});
///////////////////////////////////////////
///////////////////////////////////////////
2018-04-16 19:14:08 +00:00
var IMAGES = {}; // todo: actually USE these images
var SOUNDS = {};
2018-04-16 15:44:14 +00:00
function Preload(assets, onProgress){
var loaded = 0;
var _onAssetLoad = function(){
loaded++;
onProgress(loaded/assets.length);
};
assets.forEach(function(asset){
// Image
if(asset.image){
var img = new Image();
img.onload = _onAssetLoad;
img.src = asset.image;
2018-04-16 19:14:08 +00:00
IMAGES[asset.id] = img;
}
// Audio
if(asset.audio){
var sound = new Howl({ src:[asset.audio] });
sound.once('load', _onAssetLoad);
SOUNDS[asset.id] = sound;
2018-04-16 15:44:14 +00:00
}
});
}