forked from cocos-creator/cocos-tutorial-hot-update
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
139 lines (117 loc) · 4.58 KB
/
main.js
File metadata and controls
139 lines (117 loc) · 4.58 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
(function () {
// 在 main.js 的开头添加如下代码
if (cc.sys.isNative) {
var hotUpdateSearchPaths = cc.sys.localStorage.getItem('HotUpdateSearchPaths');
if (hotUpdateSearchPaths) {
jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths));
}
}
function boot () {
if ( !_CCSettings.debug ) {
// retrieve minified raw assets
var rawAssets = _CCSettings.rawAssets;
var assetTypes = _CCSettings.assetTypes;
for (var mount in rawAssets) {
var entries = rawAssets[mount];
for (var uuid in entries) {
var entry = entries[uuid];
var type = entry[1];
if (typeof type === 'number') {
entry[1] = assetTypes[type];
}
}
}
}
// init engine
var canvas, div;
//var width = 640, height = 480;
if (cc.sys.isBrowser) {
canvas = document.getElementById('GameCanvas');
div = document.getElementById('GameDiv');
//width = div.clientWidth;
//height = div.clientHeight;
}
function setLoadingDisplay () {
// Loading splash scene
var splash = document.getElementById('splash');
var progressBar = splash.querySelector('.progress-bar span');
var currentResCount = cc.loader.getResCount();
cc.loader.onProgress = function (completedCount, totalCount, item) {
var percent = 100 * (completedCount - currentResCount) / (totalCount - currentResCount);
if (progressBar) {
progressBar.style.width = percent.toFixed(2) + '%';
}
};
splash.style.display = 'block';
cc.director.once(cc.Director.EVENT_AFTER_SCENE_LAUNCH, function () {
splash.style.display = 'none';
});
}
var onStart = function () {
cc.view.resizeWithBrowserSize(true);
// UC browser on many android devices have performance issue with retina display
if (cc.sys.os !== cc.sys.OS_ANDROID || cc.sys.browserType !== cc.sys.BROWSER_TYPE_UC) {
cc.view.enableRetina(true);
}
//cc.view.setDesignResolutionSize(_CCSettings.designWidth, _CCSettings.designHeight, cc.ResolutionPolicy.SHOW_ALL);
if (cc.sys.isBrowser) {
setLoadingDisplay();
}
if (_CCSettings.orientation === 'landscape') {
cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
}
else if (_CCSettings.orientation === 'portrait') {
cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
}
// init assets
cc.AssetLibrary.init({
libraryPath: 'res/import',
rawAssetsBase: 'res/raw-',
rawAssets: _CCSettings.rawAssets
});
var launchScene = _CCSettings.launchScene;
// load scene
cc.director.loadScene(launchScene, null,
function () {
if (cc.sys.isBrowser) {
// show canvas
canvas.style.visibility = '';
var div = document.getElementById('GameDiv');
if (div) {
div.style.backgroundImage = '';
}
}
// play game
// cc.game.resume();
console.log('Success to load scene: ' + launchScene);
}
);
// purge
//noinspection JSUndeclaredVariable
_CCSettings = undefined;
};
var option = {
//width: width,
//height: height,
id: 'GameCanvas',
scenes: _CCSettings.scenes,
debugMode: _CCSettings.debug ? cc.DebugMode.INFO : cc.DebugMode.ERROR,
showFPS: _CCSettings.debug,
frameRate: 60,
jsList: [
_CCSettings.debug ? 'src/project.dev.js' : 'src/project.js'
],
groupList: _CCSettings.groupList,
collisionMatrix: _CCSettings.collisionMatrix
};
cc.game.run(option, onStart);
}
if (cc.sys.isBrowser) {
window.onload = boot;
}
else if (cc.sys.isNative) {
require('src/settings.js');
require('src/jsb_polyfill.js');
boot();
}
})();