drgame-cc 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,187 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="utf-8">
6
+
7
+ <title>互影派</title>
8
+
9
+ <!--http://www.html5rocks.com/en/mobile/mobifying/-->
10
+ <meta name="viewport"
11
+ content="width=device-width,user-scalable=no,initial-scale=1, minimum-scale=1,maximum-scale=1" />
12
+
13
+ <!--https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html-->
14
+ <meta name="apple-mobile-web-app-capable" content="yes">
15
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
16
+ <meta name="format-detection" content="telephone=no">
17
+ <meta name="mobile-web-app-capable" content="yes">
18
+ <!-- force webkit on 360 -->
19
+ <meta name="renderer" content="webkit" />
20
+ <meta name="force-rendering" content="webkit" />
21
+ <!-- force edge on IE -->
22
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
23
+ <meta name="msapplication-tap-highlight" content="no">
24
+
25
+ <!-- force full screen on some browser -->
26
+ <meta name="full-screen" content="yes" />
27
+ <meta name="x5-fullscreen" content="true" />
28
+ <meta name="360-fullscreen" content="true" />
29
+
30
+ <!-- force screen orientation on some browser -->
31
+ <meta name="screen-orientation" content="landscape" />
32
+ <meta name="x5-orientation" content="landscape">
33
+
34
+ <!--fix fireball/issues/3568 -->
35
+ <!--<meta name="browsermode" content="application">-->
36
+ <meta name="x5-page-mode" content="app">
37
+
38
+ <!--<link rel="apple-touch-icon" href=".png" />-->
39
+ <!--<link rel="apple-touch-icon-precomposed" href=".png" />-->
40
+
41
+ <link rel="stylesheet" type="text/css" href="style-mobile.css" />
42
+ <link rel="icon" href="favicon.ico" />
43
+ </head>
44
+
45
+ <body>
46
+ <canvas id="GameCanvas" oncontextmenu="event.preventDefault()" tabindex="-1" style="outline: none;"></canvas>
47
+ <div id="splash">
48
+ <!-- <img id="logo" src="logo.png" alt="Logo"> -->
49
+ <div id="splash-info">首次加载时间较长,请耐心等待</div>
50
+ <div id="progress-status">正在启动引擎...0%</div>
51
+ <div class="progress-bar">
52
+ <span style="width: 0%"></span>
53
+ </div>
54
+
55
+ <div id="icp">备案号:豫ICP备18029698号-5A</div>
56
+ <img id="age-rating" src="16+.png" alt="16+">
57
+ </div>
58
+ <script src="src/settings.js" charset="utf-8"></script>
59
+ <script src="vconsole.min.js"></script>
60
+ <script src="main.js" charset="utf-8"></script>
61
+
62
+ <script type="text/javascript">
63
+ (function () {
64
+ // open web debugger console
65
+ if (typeof VConsole !== 'undefined') {
66
+ window.vConsole = new VConsole();
67
+ }
68
+
69
+ var debug = window._CCSettings.debug;
70
+ var splash = document.getElementById('splash');
71
+ splash.style.display = 'block';
72
+
73
+ function loadScript(moduleName, cb) {
74
+ function scriptLoaded() {
75
+ document.body.removeChild(domScript);
76
+ domScript.removeEventListener('load', scriptLoaded, false);
77
+ cb && cb();
78
+ };
79
+ var domScript = document.createElement('script');
80
+ domScript.async = true;
81
+ domScript.src = moduleName;
82
+ domScript.addEventListener('load', scriptLoaded, false);
83
+ document.body.appendChild(domScript);
84
+ }
85
+
86
+ loadScript(debug ? 'cocos2d-js.js' : 'cocos2d-js-min.js', function () {
87
+ if (CC_PHYSICS_BUILTIN || CC_PHYSICS_CANNON) {
88
+ loadScript(debug ? 'physics.js' : 'physics-min.js', window.boot);
89
+ }
90
+ else {
91
+ window.boot();
92
+ }
93
+ });
94
+
95
+ var progressBar = document.querySelector('.progress-bar');
96
+ var progressSpan = document.querySelector('.progress-bar span');
97
+ var progressText = document.getElementById('progress-status');
98
+
99
+ var observer = new MutationObserver(function (mutations) {
100
+ mutations.forEach(function (mutation) {
101
+ if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
102
+ var width = progressSpan.style.width;
103
+ var percent = parseFloat(width);
104
+ if (percent <= 90)
105
+ progressText.innerText = "正在启动引擎..." + percent + '%';
106
+ }
107
+ });
108
+ });
109
+ if (progressSpan) {
110
+ observer.observe(progressSpan, { attributes: true });
111
+ }
112
+
113
+
114
+ })();
115
+ //桥接webview
116
+ var callbacks = [];
117
+ var isAndroid = navigator.userAgent.indexOf('Android') > -1;
118
+ function setupWebViewJavascriptBridge(callback) {
119
+ if (isAndroid) {
120
+ // 安卓
121
+ if (window.WebViewJavascriptBridge) {
122
+ callback(WebViewJavascriptBridge)
123
+ } else {
124
+ document.addEventListener('WebViewJavascriptBridgeReady', function () {
125
+ callback(WebViewJavascriptBridge)
126
+ }, false)
127
+ }
128
+ } else {
129
+ // 苹果
130
+ if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
131
+ if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
132
+ window.WVJBCallbacks = [callback];
133
+ var WVJBIframe = document.createElement('iframe');
134
+ WVJBIframe.style.display = 'none';
135
+ WVJBIframe.src = 'https://__bridge_loaded__';
136
+ document.documentElement.appendChild(WVJBIframe);
137
+ setTimeout(function () { document.documentElement.removeChild(WVJBIframe) }, 0);
138
+ }
139
+ }
140
+
141
+ setupWebViewJavascriptBridge(function (bridge) {
142
+ if (isAndroid) {
143
+ bridge.init();
144
+ }
145
+ bridge.registerHandler('app2Web', function (data, responseCallback) {
146
+ registerHandler(data, responseCallback);
147
+ });
148
+ prompt('//', 'bridge/ready');
149
+ window.bridge = bridge;
150
+ for (const callback of callbacks) {
151
+ callback();
152
+ }
153
+ callbacks = [];
154
+ });
155
+
156
+
157
+ function callHandler(api, params, callback) {
158
+ //console.log(api,params);
159
+ var tempCallback = function () {
160
+ bridge.callHandler('web2App', { 'api': api, 'params': params }, function (response) {
161
+ callback(response);
162
+ });
163
+ }
164
+ if (window.bridge) {
165
+ tempCallback();
166
+ } else {
167
+ callbacks.push(tempCallback);
168
+ }
169
+ }
170
+
171
+ // app2Web 异步函数
172
+ function registerHandler(data, responseCallback) {
173
+ console.log('registerHandler ' + data.api + " , " + data.res);
174
+ /*
175
+ // (示例)app调用web部分:
176
+ if (data.api === 'pay/requestApplePurchase') {
177
+ console.log('JS got request ', data);
178
+ }
179
+ */
180
+ window.postMessage(data, '*'); // 注意目标源安全性
181
+
182
+ }
183
+ </script>
184
+
185
+ </body>
186
+
187
+ </html>
@@ -0,0 +1,165 @@
1
+ window.boot = function () {
2
+ var settings = window._CCSettings;
3
+ window._CCSettings = undefined;
4
+ var onProgress = null;
5
+
6
+ var RESOURCES = cc.AssetManager.BuiltinBundleName.RESOURCES;
7
+ var INTERNAL = cc.AssetManager.BuiltinBundleName.INTERNAL;
8
+ var MAIN = cc.AssetManager.BuiltinBundleName.MAIN;
9
+ function setLoadingDisplay () {
10
+ // Loading splash scene
11
+ var splash = document.getElementById('splash');
12
+ var progressBar = splash.querySelector('.progress-bar span');
13
+ var progressStatus = document.getElementById('progress-status');
14
+ onProgress = function (finish, total) {
15
+ var percent = 100 * finish / total;
16
+ if (progressBar) {
17
+ progressBar.style.width = percent.toFixed(2) + '%';
18
+ }
19
+ };
20
+ splash.style.display = 'block';
21
+ // Lock displayed progress to 90% so the splash won't auto-complete.
22
+ onProgress = function (finish, total) {
23
+ var percent = 100 * finish / total;
24
+ var displayPercent = Math.min(Math.max(percent, 0), 100);
25
+ displayPercent = Math.min(displayPercent, 90);
26
+ if (progressBar) {
27
+ progressBar.style.width = displayPercent.toFixed(2) + '%';
28
+ }
29
+ };
30
+ window.setProgress = function (v,vv=undefined) {
31
+ if (progressBar) {
32
+ progressBar.style.width = v + '%';
33
+ }
34
+ if(vv!==undefined){
35
+ progressStatus.innerText = vv+v+'%';
36
+ }
37
+ };
38
+
39
+ // Prevent automatic hiding. Provide a manual API to close the loading splash.
40
+ window.closeLoading = function () {
41
+ if (splash) splash.style.display = 'none';
42
+ };
43
+ }
44
+
45
+ var onStart = function () {
46
+
47
+ cc.view.enableRetina(true);
48
+ cc.view.resizeWithBrowserSize(true);
49
+
50
+ if (cc.sys.isBrowser) {
51
+ setLoadingDisplay();
52
+ }
53
+
54
+ if (cc.sys.isMobile) {
55
+ if (settings.orientation === 'landscape') {
56
+ cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
57
+ }
58
+ else if (settings.orientation === 'portrait') {
59
+ cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
60
+ }
61
+ cc.view.enableAutoFullScreen([
62
+ cc.sys.BROWSER_TYPE_BAIDU,
63
+ cc.sys.BROWSER_TYPE_BAIDU_APP,
64
+ cc.sys.BROWSER_TYPE_WECHAT,
65
+ cc.sys.BROWSER_TYPE_MOBILE_QQ,
66
+ cc.sys.BROWSER_TYPE_MIUI,
67
+ cc.sys.BROWSER_TYPE_HUAWEI,
68
+ cc.sys.BROWSER_TYPE_UC,
69
+ ].indexOf(cc.sys.browserType) < 0&&false);
70
+ }
71
+
72
+ // Limit downloading max concurrent task to 2,
73
+ // more tasks simultaneously may cause performance draw back on some android system / browsers.
74
+ // You can adjust the number based on your own test result, you have to set it before any loading process to take effect.
75
+ if (cc.sys.isBrowser && cc.sys.os === cc.sys.OS_ANDROID) {
76
+ cc.assetManager.downloader.maxConcurrency = 2;
77
+ cc.assetManager.downloader.maxRequestsPerFrame = 2;
78
+ }
79
+
80
+ var launchScene = settings.launchScene;
81
+ var bundle = cc.assetManager.bundles.find(function (b) {
82
+ return b.getSceneInfo(launchScene);
83
+ });
84
+
85
+ bundle.loadScene(launchScene, null, onProgress,
86
+ function (err, scene) {
87
+ if (!err) {
88
+ cc.director.runSceneImmediate(scene);
89
+ if (cc.sys.isBrowser) {
90
+ // show canvas
91
+ var canvas = document.getElementById('GameCanvas');
92
+ canvas.style.visibility = '';
93
+ var div = document.getElementById('GameDiv');
94
+ if (div) {
95
+ div.style.backgroundImage = '';
96
+ }
97
+ console.log('Success to load scene: ' + launchScene);
98
+ }
99
+ }
100
+ }
101
+ );
102
+
103
+ };
104
+
105
+ var option = {
106
+ id: 'GameCanvas',
107
+ debugMode: settings.debug ? cc.debug.DebugMode.INFO : cc.debug.DebugMode.ERROR,
108
+ showFPS: settings.debug,
109
+ frameRate: 60,
110
+ groupList: settings.groupList,
111
+ collisionMatrix: settings.collisionMatrix,
112
+ };
113
+
114
+ cc.assetManager.init({
115
+ bundleVers: settings.bundleVers,
116
+ remoteBundles: settings.remoteBundles,
117
+ server: settings.server
118
+ });
119
+
120
+ var bundleRoot = [INTERNAL];
121
+ settings.hasResourcesBundle && bundleRoot.push(RESOURCES);
122
+
123
+ var count = 0;
124
+ function cb (err) {
125
+ if (err) return console.error(err.message, err.stack);
126
+ count++;
127
+ if (count === bundleRoot.length + 1) {
128
+ cc.assetManager.loadBundle(MAIN, function (err) {
129
+ if (!err) {
130
+ cc.macro.ENABLE_TRANSPARENT_CANVAS = true;
131
+ cc.game.run(option, onStart);
132
+ }
133
+ });
134
+ }
135
+ }
136
+
137
+ cc.assetManager.loadScript(settings.jsList.map(function (x) { return 'src/' + x;}), cb);
138
+
139
+ for (var i = 0; i < bundleRoot.length; i++) {
140
+ cc.assetManager.loadBundle(bundleRoot[i], cb);
141
+ }
142
+ };
143
+
144
+ if (window.jsb) {
145
+ var isRuntime = (typeof loadRuntime === 'function');
146
+ if (isRuntime) {
147
+ require('src/settings.js');
148
+ require('src/cocos2d-runtime.js');
149
+ if (CC_PHYSICS_BUILTIN || CC_PHYSICS_CANNON) {
150
+ require('src/physics.js');
151
+ }
152
+ require('jsb-adapter/engine/index.js');
153
+ }
154
+ else {
155
+ require('src/settings.js');
156
+ require('src/cocos2d-jsb.js');
157
+ if (CC_PHYSICS_BUILTIN || CC_PHYSICS_CANNON) {
158
+ require('src/physics.js');
159
+ }
160
+ require('jsb-adapter/jsb-engine.js');
161
+ }
162
+
163
+ cc.macro.CLEANUP_IMAGE_CACHE = true;
164
+ window.boot();
165
+ }