Skip to content

Commit f9c18be

Browse files
author
SeanLin
committed
Merge pull request cocos2d#514 from Wu-Hao/iss1295DOMConverter
fix bug for dom, added support for single engine file
2 parents 90cc8fe + e81e5a3 commit f9c18be

File tree

8 files changed

+86
-12
lines changed

8 files changed

+86
-12
lines changed

Demo/HelloDomMenu/cocos2d.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,26 @@
3333
frameRate:60,
3434
tag:'gameCanvas', //the dom element to run cocos2d on
3535
engineDir:'../../cocos2d/',
36+
//SingleEngineFile:'',
3637
appFiles:['src/myApp.js']
3738
};
3839
window.addEventListener('DOMContentLoaded', function () {
3940
//first load engine file if specified
4041
var s = d.createElement('script');
41-
s.src = c.engineDir + 'platform/jsloader.js';
42+
/*********Delete this section if you have packed all files into one*******/
43+
if (c.SingleEngineFile && !c.engineDir) {
44+
s.src = c.SingleEngineFile;
45+
}
46+
else if (c.engineDir && !c.SingleEngineFile) {
47+
s.src = c.engineDir + 'platform/jsloader.js';
48+
}
49+
else {
50+
alert('You must specify either the single engine file OR the engine directory in "cocos2d.js"');
51+
}
52+
/*********Delete this section if you have packed all files into one*******/
53+
54+
//s.src = 'Packed_Release_File.js'; //IMPORTANT: Un-comment this line if you have packed all files into one
55+
4256
d.body.appendChild(s);
4357
s.c = c;
4458
s.id = 'cocos2d-html5';

Demo/NativeClientDemo/cocos2d.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,26 @@
3434
frameRate:60,
3535
tag:'gameCanvas', //the dom element to run cocos2d on
3636
engineDir:'../../cocos2d/',
37+
//SingleEngineFile:'',
3738
appFiles:['src/NativeClient.js']
3839
};
3940
window.addEventListener('DOMContentLoaded', function () {
4041
//first load engine file if specified
4142
var s = d.createElement('script');
42-
s.src = c.engineDir + 'platform/jsloader.js';
43+
/*********Delete this section if you have packed all files into one*******/
44+
if (c.SingleEngineFile && !c.engineDir) {
45+
s.src = c.SingleEngineFile;
46+
}
47+
else if (c.engineDir && !c.SingleEngineFile) {
48+
s.src = c.engineDir + 'platform/jsloader.js';
49+
}
50+
else {
51+
alert('You must specify either the single engine file OR the engine directory in "cocos2d.js"');
52+
}
53+
/*********Delete this section if you have packed all files into one*******/
54+
55+
//s.src = 'Packed_Release_File.js'; //IMPORTANT: Un-comment this line if you have packed all files into one
56+
4357
d.body.appendChild(s);
4458
s.c = c;
4559
s.id = 'cocos2d-html5';

HelloHTML5World/cocos2d.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
frameRate:60,
3434
tag:'gameCanvas', //the dom element to run cocos2d on
3535
engineDir:'../cocos2d/',
36+
//SingleEngineFile:'',
3637
appFiles:[
3738
'src/resource.js',
3839
'src/myApp.js'//add your own files in order here
@@ -41,7 +42,20 @@
4142
window.addEventListener('DOMContentLoaded', function () {
4243
//first load engine file if specified
4344
var s = d.createElement('script');
44-
s.src = c.engineDir + 'platform/jsloader.js';
45+
/*********Delete this section if you have packed all files into one*******/
46+
if (c.SingleEngineFile && !c.engineDir) {
47+
s.src = c.SingleEngineFile;
48+
}
49+
else if (c.engineDir && !c.SingleEngineFile) {
50+
s.src = c.engineDir + 'platform/jsloader.js';
51+
}
52+
else {
53+
alert('You must specify either the single engine file OR the engine directory in "cocos2d.js"');
54+
}
55+
/*********Delete this section if you have packed all files into one*******/
56+
57+
//s.src = 'Packed_Release_File.js'; //IMPORTANT: Un-comment this line if you have packed all files into one
58+
4559
d.body.appendChild(s);
4660
s.c = c;
4761
s.id = 'cocos2d-html5';

cocos2d/base_nodes/CCdomNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ cc.DOM.addMethods = function (x) {
3333
};
3434
cc.DOM.methods = {
3535
setPosition:function (x, y) {
36-
if (y != 0) {
36+
if (y != null) {
3737
this._position.x = x;
3838
this._position.y = y;
3939
//this._position = cc.p(newPosOrxValue,yValue);

cocos2d/build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<file name="tileMap_parallax_nodes/CCTMXObjectGroup.js"/>
8888
<file name="tileMap_parallax_nodes/CCTMXLayer.js"/>
8989
<file name="tileMap_parallax_nodes/CCParallaxNode.js"/>
90+
<file name="platform/jsloader.js"/>
9091
</sources>
9192
<sources dir="${basedir}/../CocosDenshion">
9293
<file name="SimpleAudioEngine.js"/>

cocos2d/platform/jsloader.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2525
THE SOFTWARE.
2626
****************************************************************************/
27-
var cc = cc || cc || {};
2827
(function () {
2928
var engine = [
30-
'platform/miniFramework.js',
3129
'platform/CCClass.js',
30+
'platform/miniFramework.js',
3231
'platform/CCCommon.js',
3332
'platform/platform.js',
3433
'platform/ZipUtils.js',
@@ -109,12 +108,17 @@ var cc = cc || cc || {};
109108
];
110109
var d = document;
111110
var c = d.querySelector('#cocos2d-html5').c;
111+
if (!c.engineDir) {
112+
engine = [];
113+
}
114+
else {
115+
engine.forEach(function (e, i) {
116+
engine[i] = c.engineDir + e;
117+
});
118+
}
112119
if (c.box2d)
113120
engine.push('../box2d/box2d.js');
114121
var loaded = 0;
115-
engine.forEach(function (e, i) {
116-
engine[i] = c.engineDir + e;
117-
});
118122
var que = engine.concat(c.appFiles);
119123
que.push('main.js');
120124
if (navigator.userAgent.indexOf("Trident/5") > -1) {

template/cocos2d.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
(function () {
2828
var d = document;
2929
var c = {
30-
menuType:'canvas', //whether to use canvas mode menu or dom menu
3130
COCOS2D_DEBUG:2, //0 to turn debug off, 1 for basic debug, and 2 for full debug
3231
box2d:false,
3332
showFPS:true,
3433
frameRate:60,
3534
tag:'gameCanvas', //the dom element to run cocos2d on
3635
engineDir:'../cocos2d/',
36+
//SingleEngineFile:'',
3737
appFiles:[
3838
'src/resource.js',
3939
'src/myApp.js'//add your own files in order here
@@ -42,7 +42,20 @@
4242
window.addEventListener('DOMContentLoaded', function () {
4343
//first load engine file if specified
4444
var s = d.createElement('script');
45-
s.src = c.engineDir + 'platform/jsloader.js';
45+
/*********Delete this section if you have packed all files into one*******/
46+
if (c.SingleEngineFile && !c.engineDir) {
47+
s.src = c.SingleEngineFile;
48+
}
49+
else if (c.engineDir && !c.SingleEngineFile) {
50+
s.src = c.engineDir + 'platform/jsloader.js';
51+
}
52+
else {
53+
alert('You must specify either the single engine file OR the engine directory in "cocos2d.js"');
54+
}
55+
/*********Delete this section if you have packed all files into one*******/
56+
57+
//s.src = 'Packed_Release_File.js'; //IMPORTANT: Un-comment this line if you have packed all files into one
58+
4659
d.body.appendChild(s);
4760
s.c = c;
4861
s.id = 'cocos2d-html5';

tests/cocos2d.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
frameRate:60,
3535
tag:'gameCanvas', //the dom element to run cocos2d on
3636
engineDir:'../cocos2d/',
37+
//SingleEngineFile:'',
3738
appFiles:[//'src/AppDelegate.js',
3839
'src/testbasic.js',
3940
'src/testResource.js',
@@ -76,7 +77,20 @@
7677
window.addEventListener('DOMContentLoaded', function () {
7778
//first load engine file if specified
7879
var s = d.createElement('script');
79-
s.src = c.engineDir + 'platform/jsloader.js';
80+
/*********Delete this section if you have packed all files into one*******/
81+
if (c.SingleEngineFile && !c.engineDir) {
82+
s.src = c.SingleEngineFile;
83+
}
84+
else if (c.engineDir && !c.SingleEngineFile) {
85+
s.src = c.engineDir + 'platform/jsloader.js';
86+
}
87+
else {
88+
alert('You must specify either the single engine file OR the engine directory in "cocos2d.js"');
89+
}
90+
/*********Delete this section if you have packed all files into one*******/
91+
92+
//s.src = 'Packed_Release_File.js'; //IMPORTANT: Un-comment this line if you have packed all files into one
93+
8094
d.body.appendChild(s);
8195
s.c = c;
8296
s.id = 'cocos2d-html5';

0 commit comments

Comments
 (0)