-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
74 lines (65 loc) · 1.91 KB
/
main.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
70
71
72
73
74
/* eslint-disable */
;
(function () {
window.VIEW_HEIGHT = document.documentElement['clientHeight'] * 320 / document.documentElement['clientWidth'];
var config = {
showFPS: true,
dpi: 2,
canvasId: 'TinyCanvas',
renderOptions: {
backgroundColor: 0x7ac9e5
}
};
if (navigator.userAgent.toLowerCase().indexOf('mobile') > -1) {
config._is4S = window.VIEW_HEIGHT <= 480;
config._isiPad = window.VIEW_HEIGHT <= 400;
}
Tiny.app = new Tiny.Application(config);
var main = {
init: function () {
console.log('init');
this.resourceLoad();
},
resourceLoad: function () {
var resources = [];
for (var key in RESOURCES) {
resources.push(RESOURCES[key]);
}
var progress = document.getElementById('progress');
var percent = document.getElementById('percent');
var hole = document.getElementById('hole');
Tiny.Loader.run({
resources: resources,
onProgress: function (pre) {
console.log('percent:', pre + '%');
var num = ~~pre;
//更新UI
percent.innerHTML = num + '%';
progress.style.marginTop = (100 - num) + '%';
},
onAllComplete: function () {
console.log('all complete');
//clear DOM
var body = document.body;
body.removeChild(hole);
body.removeChild(percent);
body.removeChild(progress.parentNode);
Tiny.app.run(new StartLayer());
}
});
}
};
main.init();
function bridgeInit() {
document.addEventListener('pause', function (e) {
Tiny.app.pause();
window.GAME_BRIDGE && window.GAME_BRIDGE.gamePause();
}, false);
document.addEventListener('resume', function (e) {
Tiny.app.resume();
}, false);
}
window.AlipayJSBridge ? bridgeInit() : document.addEventListener('AlipayJSBridgeReady', function () {
bridgeInit();
});
})();