forked from github/game-off-2013
-
Notifications
You must be signed in to change notification settings - Fork 1
/
loadscreen.js
69 lines (57 loc) · 2.04 KB
/
loadscreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"use strict";
define([], function() {
function LoadScreen( parent ) {
var progressContainer = document.createElement("div");
progressContainer.className = "centered";
parent.appendChild( progressContainer );
var element = document.getElementById("status");
element.innerHTML = "loading assets...";
function initialize( id ) {
var elementId = "preload_"+id;
var element = getProgressElement( elementId );
if( !element ) {
element = createProgressElement(elementId);
element.value = 0;
}
}
function update(id, percent) {
var elementId = "preload_"+id;
var element = getProgressElement( elementId );
element.value = percent;
}
function getProgressElement(id) {
return document.getElementById(id);
}
function createProgressElement(id) {
var result = document.createElement("progress");
result.max = 100;
result.id = id;
result.className = "assetProgress";
progressContainer.appendChild( result );
return result;
}
function close() {
parent.removeChild( progressContainer );
parent.removeChild( document.getElementById("logo") );
document.body.removeChild( document.getElementById("status"));
createGameScreen();
}
function createGameScreen() {
var sceneElement = document.createElement("div");
sceneElement.id = "scene";
document.body.appendChild( sceneElement );
var messageElement = document.createElement("div");
messageElement.id = "message";
messageElement.style.display = "none";
document.body.appendChild( messageElement );
}
return {
initialize: initialize,
update: update,
close: close,
};
}
return {
LoadScreen:LoadScreen,
};
});