Skip to content

Commit e0c7c45

Browse files
author
SeanLin
committed
Merge pull request #181 from xingsenma/MoonWarriors2
fixed #2351: Improve MoonWarriors performance for mobile browsers
2 parents 6a3c81e + 86cdc05 commit e0c7c45

25 files changed

+1698
-352
lines changed

games/MoonWarriors/MoonWarriors-compress.js

Lines changed: 952 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

games/MoonWarriors/MoonWarriors-html5.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ var MW = MW || {};
3535
showFPS:true,
3636
loadExtension:true,
3737
frameRate:60,
38+
renderMode:1, //Choose of RenderMode: 0(default), 1(Canvas only), 2(WebGL only)
3839
tag:'gameCanvas', //the dom element to run cocos2d on
3940
engineDir:'../../../cocos2d/',
41+
/*SingleEngineFile:'MoonWarriors-compress.js',*/
4042
appFiles:[
4143
'src/Resource.js',
4244
'src/config/GameConfig.js',
@@ -56,7 +58,8 @@ var MW = MW || {};
5658
'src/SettingsLayer.js',
5759
'src/SysMenu.js',
5860
'src/HitEffect.js',
59-
'src/SparkEffect.js'
61+
'src/SparkEffect.js',
62+
'src/Background.js'
6063
]
6164
};
6265

games/MoonWarriors/MoonWarriors-jsb.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ var appFiles = [
4949
'src/SettingsLayer.js',
5050
'src/SysMenu.js',
5151
'src/SparkEffect.js',
52-
'src/HitEffect.js'
52+
'src/HitEffect.js',
53+
'src/Background.js'
5354
];
5455

5556
cc.dumpConfig();

games/MoonWarriors/build.xml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?xml version="1.0"?>
2+
<project name="Javascript compress project" basedir="." default="compile_test_advanced">
3+
4+
<taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask"
5+
classpath="${basedir}/../../../tools/compiler/compiler.jar"/>
6+
7+
8+
<target name="compile_test_advanced">
9+
<jscomp compilationLevel="advanced" warning="quiet"
10+
debug="false" output="MoonWarriors-compress.js">
11+
<externs dir="${basedir}/../../../cocos2d">
12+
<file name="cocos2d_externs.js"/>
13+
</externs>
14+
<sources dir="${basedir}/../../../cocos2d">
15+
<file name="platform/CCClass.js"/>
16+
<file name="platform/CCCommon.js"/>
17+
<file name="platform/miniFramework.js"/>
18+
<file name="platform/ZipUtils.js"/>
19+
<file name="platform/base64.js"/>
20+
<file name="platform/gzip.js"/>
21+
<file name="platform/CCMacro.js"/>
22+
<file name="platform/CCFileUtils.js"/>
23+
<file name="platform/CCTypes.js"/>
24+
<file name="platform/CCAccelerometer.js"/>
25+
<file name="platform/CCEGLView.js"/>
26+
<file name="platform/CCImage.js"/>
27+
<file name="platform/zlib.min.js"/>
28+
<file name="cocoa/CCGeometry.js"/>
29+
<file name="platform/Sys.js"/>
30+
<file name="platform/CCConfig.js"/>
31+
<file name="cocoa/CCNS.js"/>
32+
<file name="cocoa/CCSet.js"/>
33+
<file name="kazmath/vec2.js"/>
34+
<file name="kazmath/vec3.js"/>
35+
<file name="kazmath/vec4.js"/>
36+
<file name="kazmath/utility.js"/>
37+
<file name="kazmath/ray2.js"/>
38+
<file name="kazmath/mat3.js"/>
39+
<file name="kazmath/mat4.js"/>
40+
<file name="kazmath/plane.js"/>
41+
<file name="kazmath/quaternion.js"/>
42+
<file name="kazmath/aabb.js"/>
43+
<file name="kazmath/GL/mat4stack.js"/>
44+
<file name="kazmath/GL/matrix.js"/>
45+
<file name="cocoa/CCAffineTransform.js"/>
46+
<file name="support/CCPointExtension.js"/>
47+
<file name="support/CCPNGReader.js"/>
48+
<file name="support/CCTIFFReader.js"/>
49+
<file name="support/CCUserDefault.js"/>
50+
<file name="support/CCVertex.js"/>
51+
<file name="support/TransformUtils.js"/>
52+
<file name="shaders/CCShaders.js"/>
53+
<file name="shaders/CCGLProgram.js"/>
54+
<file name="shaders/CCGLStateCache.js"/>
55+
<file name="shaders/CCShaderCache.js"/>
56+
<file name="base_nodes/CCNode.js"/>
57+
<file name="base_nodes/CCdomNode.js"/>
58+
<file name="base_nodes/CCAtlasNode.js"/>
59+
<file name="textures/CCTexture2D.js"/>
60+
<file name="textures/CCTextureCache.js"/>
61+
<file name="textures/CCTextureAtlas.js"/>
62+
<file name="misc_nodes/CCRenderTexture.js"/>
63+
<file name="misc_nodes/CCProgressTimer.js"/>
64+
<file name="misc_nodes/CCClippingNode.js"/>
65+
<file name="misc_nodes/CCMotionStreak.js"/>
66+
<file name="effects/CCGrid.js"/>
67+
<file name="effects/CCGrabber.js"/>
68+
<file name="actions/CCAction.js"/>
69+
<file name="actions/CCActionInterval.js"/>
70+
<file name="actions/CCActionInstant.js"/>
71+
<file name="actions/CCActionManager.js"/>
72+
<file name="actions/CCActionProgressTimer.js"/>
73+
<file name="actions/CCActionCamera.js"/>
74+
<file name="actions/CCActionEase.js"/>
75+
<file name="actions/CCActionGrid.js"/>
76+
<file name="actions/CCActionGrid3D.js"/>
77+
<file name="actions/CCActionPageTurn3D.js"/>
78+
<file name="actions/CCActionTiledGrid.js"/>
79+
<file name="actions/CCActionTween.js"/>
80+
<file name="actions/CCActionCatmullRom.js"/>
81+
<file name="layers_scenes_transitions_nodes/CCScene.js"/>
82+
<file name="layers_scenes_transitions_nodes/CCLayer.js"/>
83+
<file name="layers_scenes_transitions_nodes/CCTransition.js"/>
84+
<file name="layers_scenes_transitions_nodes/CCTransitionProgress.js"/>
85+
<file name="layers_scenes_transitions_nodes/CCTransitionPageTurn.js"/>
86+
<file name="sprite_nodes/CCSprite.js"/>
87+
<file name="sprite_nodes/CCAnimation.js"/>
88+
<file name="sprite_nodes/CCAnimationCache.js"/>
89+
<file name="sprite_nodes/CCSpriteFrame.js"/>
90+
<file name="sprite_nodes/CCSpriteFrameCache.js"/>
91+
<file name="sprite_nodes/CCSpriteBatchNode.js"/>
92+
<file name="label_nodes/CCLabelAtlas.js"/>
93+
<file name="label_nodes/CCLabelTTF.js"/>
94+
<file name="label_nodes/CCLabelBMFont.js"/>
95+
<file name="particle_nodes/CCParticleSystem.js"/>
96+
<file name="particle_nodes/CCParticleBatchNode.js"/>
97+
<file name="particle_nodes/CCParticleSystemQuad.js"/>
98+
<file name="particle_nodes/CCParticleExamples.js"/>
99+
<file name="touch_dispatcher/CCTouchDelegateProtocol.js"/>
100+
<file name="touch_dispatcher/CCTouchHandler.js"/>
101+
<file name="touch_dispatcher/CCTouchDispatcher.js"/>
102+
<file name="touch_dispatcher/CCMouseDispatcher.js"/>
103+
<file name="keyboard_dispatcher/CCKeyboardDelegate.js"/>
104+
<file name="keyboard_dispatcher/CCKeyboardDispatcher.js"/>
105+
<file name="text_input_node/CCIMEDispatcher.js"/>
106+
<file name="text_input_node/CCTextFieldTTF.js"/>
107+
<file name="draw_nodes/CCDrawNode.js" />
108+
<file name="physics_nodes/CCPhysicsDebugNode.js" />
109+
<file name="physics_nodes/CCPhysicsSprite.js" />
110+
<file name="CCConfiguration.js"/>
111+
<file name="CCDirector.js"/>
112+
<file name="CCCamera.js"/>
113+
<file name="CCScheduler.js"/>
114+
<file name="CCLoader.js"/>
115+
<file name="CCDrawingPrimitives.js"/>
116+
<file name="platform/CCApplication.js"/>
117+
<file name="platform/CCSAXParser.js"/>
118+
<file name="platform/AppControl.js"/>
119+
<file name="menu_nodes/CCMenuItem.js"/>
120+
<file name="menu_nodes/CCMenu.js"/>
121+
<file name="tileMap_parallax_nodes/CCTMXTiledMap.js"/>
122+
<file name="tileMap_parallax_nodes/CCTMXXMLParser.js"/>
123+
<file name="tileMap_parallax_nodes/CCTMXObjectGroup.js"/>
124+
<file name="tileMap_parallax_nodes/CCTMXLayer.js"/>
125+
<file name="tileMap_parallax_nodes/CCParallaxNode.js"/>
126+
<!--<file name="platform/jsloader.js"/>-->
127+
</sources>
128+
<sources dir="${basedir}/../../../CocosDenshion">
129+
<file name="SimpleAudioEngine.js"/>
130+
</sources>
131+
<sources dir="${basedir}">
132+
<file name="MoonWarriors-html5.js"/>
133+
<file name="src/Resource.js"/>
134+
<file name="src/config/GameConfig.js"/>
135+
<file name="src/config/EnemyType.js"/>
136+
<file name="src/config/Level.js"/>
137+
<file name="src/Effect.js"/>
138+
<file name="src/Bullet.js"/>
139+
<file name="src/Enemy.js"/>
140+
<file name="src/Explosion.js"/>
141+
<file name="src/Ship.js"/>
142+
<file name="src/LevelManager.js"/>
143+
<file name="src/GameController.js"/>
144+
<file name="src/GameControlMenu.js"/>
145+
<file name="src/GameLayer.js"/>
146+
<file name="src/GameOver.js"/>
147+
<file name="src/AboutLayer.js"/>
148+
<file name="src/SettingsLayer.js"/>
149+
<file name="src/SysMenu.js"/>
150+
<file name="src/HitEffect.js"/>
151+
<file name="src/SparkEffect.js"/>
152+
<file name="src/Background.js"/>
153+
<file name="main.js"/>
154+
</sources>
155+
</jscomp>
156+
</target>
157+
</project>

games/MoonWarriors/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>Cocos2d-html5 Show Case - MoonWarriors</title>
5+
<meta name="viewport" content="width=320,user-scalable=no"/>
56
<meta charset="utf-8"/>
67
<meta name="author" content="html5china"/>
78
</head>

games/MoonWarriors/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var cocos2dApp = cc.Application.extend({
3131
this._super();
3232
this.startScene = scene;
3333
cc.COCOS2D_DEBUG = this.config.COCOS2D_DEBUG;
34-
cc.setup(this.config.tag);
34+
cc.setup(this.config['tag']);
3535
cc.AppController.shareAppController().didFinishLaunchingWithOptions();
3636
},
3737
applicationDidFinishLaunching:function () {
@@ -41,7 +41,7 @@ var cocos2dApp = cc.Application.extend({
4141
cc.EGLView.getInstance().setDesignResolutionSize(320,480,cc.RESOLUTION_POLICY.SHOW_ALL);
4242

4343
// turn on display FPS
44-
director.setDisplayStats(this.config.showFPS);
44+
director.setDisplayStats(this.config['showFPS']);
4545

4646
// set FPS. the default value is 1.0/60 if you don't call this
4747
director.setAnimationInterval(1.0 / this.config.frameRate);
-1.6 MB
Binary file not shown.
-1.21 MB
Binary file not shown.
-387 KB
Binary file not shown.
-474 KB
Binary file not shown.

games/MoonWarriors/res/b01.plist

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>frames</key>
6+
<dict>
7+
<key>lvl1_map1.png</key>
8+
<dict>
9+
<key>frame</key>
10+
<string>{{0,0},{240,240}}</string>
11+
<key>offset</key>
12+
<string>{0,0}</string>
13+
<key>rotated</key>
14+
<false/>
15+
<key>sourceColorRect</key>
16+
<string>{{0,0},{240,240}}</string>
17+
<key>sourceSize</key>
18+
<string>{240,240}</string>
19+
</dict>
20+
<key>lvl1_map2.png</key>
21+
<dict>
22+
<key>frame</key>
23+
<string>{{240,0},{240,240}}</string>
24+
<key>offset</key>
25+
<string>{0,0}</string>
26+
<key>rotated</key>
27+
<false/>
28+
<key>sourceColorRect</key>
29+
<string>{{0,0},{240,240}}</string>
30+
<key>sourceSize</key>
31+
<string>{240,240}</string>
32+
</dict>
33+
<key>lvl1_map3.png</key>
34+
<dict>
35+
<key>frame</key>
36+
<string>{{0,240},{240,240}}</string>
37+
<key>offset</key>
38+
<string>{0,0}</string>
39+
<key>rotated</key>
40+
<false/>
41+
<key>sourceColorRect</key>
42+
<string>{{0,0},{240,240}}</string>
43+
<key>sourceSize</key>
44+
<string>{240,240}</string>
45+
</dict>
46+
<key>lvl1_map4.png</key>
47+
<dict>
48+
<key>frame</key>
49+
<string>{{240,240},{240,240}}</string>
50+
<key>offset</key>
51+
<string>{0,0}</string>
52+
<key>rotated</key>
53+
<false/>
54+
<key>sourceColorRect</key>
55+
<string>{{0,0},{240,240}}</string>
56+
<key>sourceSize</key>
57+
<string>{240,240}</string>
58+
</dict>
59+
</dict>
60+
<key>metadata</key>
61+
<dict>
62+
<key>format</key>
63+
<integer>2</integer>
64+
<key>realTextureFileName</key>
65+
<string>b01.png</string>
66+
<key>size</key>
67+
<string>{480,480}</string>
68+
<key>textureFileName</key>
69+
<string>b01.png</string>
70+
</dict>
71+
</dict>
72+
</plist>

games/MoonWarriors/res/loading.png

-45.5 KB
Loading

games/MoonWarriors/src/Background.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
var BackSky = cc.Sprite.extend({
2+
active:true,
3+
ctor:function () {
4+
this._super();
5+
this.initWithSpriteFrameName("bg01.png");
6+
this.setAnchorPoint(cc.p(0, 0));
7+
},
8+
destroy:function () {
9+
this.setVisible(false);
10+
this.active = false;
11+
}
12+
});
13+
14+
BackSky.create = function () {
15+
var background = new BackSky();
16+
g_sharedGameLayer.addChild(background, -10);
17+
MW.CONTAINER.BACKSKYS.push(background);
18+
return background;
19+
};
20+
21+
BackSky.getOrCreate = function () {
22+
var selChild = null;
23+
for (var j = 0; j < MW.CONTAINER.BACKSKYS.length; j++) {
24+
selChild = MW.CONTAINER.BACKSKYS[j];
25+
if (selChild.active == false) {
26+
selChild.setVisible(true);
27+
selChild.active = true;
28+
return selChild;
29+
}
30+
}
31+
selChild = BackSky.create();
32+
return selChild;
33+
};
34+
35+
36+
BackSky.preSet = function () {
37+
var background = null;
38+
for (var i = 0; i < 2; i++) {
39+
background = BackSky.create();
40+
background.setVisible(false);
41+
background.active = false;
42+
}
43+
};
44+
45+
var BackTileMapLvl1 = [
46+
"lvl1_map1.png",
47+
"lvl1_map2.png",
48+
"lvl1_map3.png",
49+
"lvl1_map4.png"
50+
];
51+
52+
var BackTileMap = cc.Sprite.extend({
53+
active:true,
54+
ctor:function (frameName) {
55+
this._super();
56+
this.initWithSpriteFrameName(frameName);
57+
this.setAnchorPoint(cc.p(0.5, 0));
58+
},
59+
destroy:function () {
60+
this.setVisible(false);
61+
this.active = false;
62+
}
63+
});
64+
65+
BackTileMap.create = function (frameName) {
66+
var backTileMap = new BackTileMap(frameName);
67+
g_sharedGameLayer.addChild(backTileMap, -9);
68+
MW.CONTAINER.BACKTILEMAPS.push(backTileMap);
69+
return backTileMap;
70+
};
71+
72+
BackTileMap.getOrCreate = function () {
73+
var selChild = null;
74+
for (var j = 0; j < MW.CONTAINER.BACKTILEMAPS.length; j++) {
75+
selChild = MW.CONTAINER.BACKTILEMAPS[j];
76+
if (selChild.active == false) {
77+
selChild.setVisible(true);
78+
selChild.active = true;
79+
return selChild;
80+
}
81+
}
82+
selChild = BackTileMap.create(BackTileMapLvl1[0|Math.random()*4]);
83+
return selChild;
84+
};
85+
86+
87+
BackTileMap.preSet = function () {
88+
var backTileMap = null;
89+
for (var i = 0; i < BackTileMapLvl1.length; i++) {
90+
backTileMap = BackTileMap.create(BackTileMapLvl1[i]);
91+
backTileMap.setVisible(false);
92+
backTileMap.active = false;
93+
}
94+
};
95+

0 commit comments

Comments
 (0)