├── .gitignore
├── LICENSE
├── README.md
├── build.xml
├── flash
├── customClick.fla
├── customClick.swf
├── effect.fla
├── effect.swf
├── gameBubbles.fla
├── gameBubbles.swf
├── gameFruitsLink.fla
├── gameFruitsLink.swf
├── gamePhysics.fla
├── gamePhysics.swf
├── gamePopStars.fla
├── gamePopStars.swf
├── gameShooters.fla
├── gameShooters.swf
├── gameTimberQiang.fla
├── gameTimberQiang.swf
├── monkeyRun.fla
├── monkeyRun.swf
├── sceneNav.fla
├── sceneNav.swf
├── scrollingBG.fla
├── scrollingBG.swf
├── skeletonControl.fla
├── skeletonControl.swf
├── tiledImage.fla
├── tiledImage.swf
├── uiBmFont.fla
├── uiBmFont.swf
├── uiButton.fla
├── uiButton.swf
├── uiInput.fla
├── uiInput.swf
├── uiPanel.fla
├── uiPanel.swf
├── uiProgress.fla
└── uiProgress.swf
├── flax.png
├── index.html
├── main.js
├── project.json
├── res
├── boss.plist
├── boss.png
├── customClick.plist
├── customClick.png
├── effect.plist
├── effect.png
├── font
│ └── ANTSYPAN.TTF
├── gameBubbles.b1.jpg
├── gameBubbles.bg.jpg
├── gameBubbles.plist
├── gameBubbles.png
├── gameFruitsLink.bg.jpg
├── gameFruitsLink.plist
├── gameFruitsLink.png
├── gamePhysics.bg.jpg
├── gamePhysics.plist
├── gamePhysics.png
├── gamePopStars.bg.jpg
├── gamePopStars.plist
├── gamePopStars.png
├── gameShooters.plist
├── gameShooters.png
├── gameTimberQiang.Symbol1.jpg
├── gameTimberQiang.plist
├── gameTimberQiang.png
├── heros.bg.jpg
├── heros.plist
├── heros.png
├── locale
│ ├── en.json
│ └── zh.json
├── logo.png
├── monkeyRun.plist
├── monkeyRun.png
├── music
│ ├── bg.mp3
│ ├── chop.mp3
│ ├── gun0.mp3
│ ├── gun1.mp3
│ ├── monkey0.mp3
│ ├── monkey1.mp3
│ └── scream.wav
├── physics.bg.jpg
├── physics.plist
├── physics.png
├── rotate.png
├── sceneNav.plist
├── sceneNav.png
├── scrollingBG.bg.jpg
├── scrollingBG.bg0.jpg
├── scrollingBG.bg1.jpg
├── scrollingBG.plist
├── scrollingBG.png
├── skeletonControl.plist
├── skeletonControl.png
├── tiledImage.plist
├── tiledImage.png
├── uiBmFont.plist
├── uiBmFont.png
├── uiButton.asset1.png
├── uiButton.asset3.png
├── uiButton.plist
├── uiButton.png
├── uiInput.plist
├── uiInput.png
├── uiPanel.PanelBack.jpg
├── uiPanel.plist
├── uiPanel.png
├── uiProgress.plist
└── uiProgress.png
└── src
├── AnimationAndAnchor.js
├── BaseScene.js
├── Config.js
├── CustomClickTest.js
├── EffectAndPool.js
├── GameBubbles.js
├── GameFruitsLink.js
├── GamePhysics.js
├── GamePopStars.js
├── GameShooters.js
├── GameTimberQiang.js
├── ScrollingBGTest.js
├── SkeletonAndControl.js
├── TiledImageTest.js
├── UIBMFont.js
├── UIButton.js
├── UIInput.js
├── UIPanel.js
├── UIProgress.js
├── flax
├── Flax.js
├── core
│ ├── Animator.js
│ ├── AssetsManager.js
│ ├── Button.js
│ ├── DebugDraw.js
│ ├── FlaxLoader.js
│ ├── FlaxSprite.js
│ ├── Image.js
│ ├── InputManager.js
│ ├── Label.js
│ ├── MovieClip.js
│ ├── Physics.js
│ └── ProgressBar.js
├── game
│ ├── Color.js
│ ├── Gun.js
│ ├── Gunner.js
│ ├── LinkFinder.js
│ ├── ObjectPool.js
│ ├── Preloader.js
│ ├── ScrollPane.js
│ ├── ScrollingBG.js
│ ├── SoundButton.js
│ ├── TileMap.js
│ ├── TiledImage.js
│ └── UserData.js
├── module
│ ├── EnemyWaveModule.js
│ ├── HealthModule.js
│ ├── MoveModule.js
│ ├── PhysicsModule.js
│ ├── ScreenLayoutModule.js
│ └── TileMapModule.js
└── signal
│ ├── Signal.js
│ ├── SignalBinding.js
│ └── wrapper.js
└── resource.js
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | .idea/scopes/scope_settings.xml
3 |
4 | .idea/workspace.xml
5 |
6 | .idea/Flax-js-examples.iml
7 |
8 | .idea/encodings.xml
9 |
10 | .idea/vcs.xml
11 |
12 | .idea/misc.xml
13 |
14 | .idea/modules.xml
15 |
16 | .cocos-project.json
17 |
18 | CMakeLists.txt
19 |
20 | flax.png
21 |
22 | frameworks/*
23 |
24 | runtime/*
25 |
26 | tools/*
27 |
28 | publish/*
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 yangxi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Flax-js-examples
2 | ================
3 | Examples for Flax-js
4 |
5 | Online Demo
6 | ===========
7 | http://longames.com/h5/example/
8 |
9 | Flax-js
10 | =======
11 | https://github.com/longyangxi/Flax-js
12 |
13 | Home
14 | ====
15 | http://flax.longames.com
16 |
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
8 |
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 |
--------------------------------------------------------------------------------
/flash/customClick.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/customClick.fla
--------------------------------------------------------------------------------
/flash/customClick.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/customClick.swf
--------------------------------------------------------------------------------
/flash/effect.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/effect.fla
--------------------------------------------------------------------------------
/flash/effect.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/effect.swf
--------------------------------------------------------------------------------
/flash/gameBubbles.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/gameBubbles.fla
--------------------------------------------------------------------------------
/flash/gameBubbles.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/gameBubbles.swf
--------------------------------------------------------------------------------
/flash/gameFruitsLink.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/gameFruitsLink.fla
--------------------------------------------------------------------------------
/flash/gameFruitsLink.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/gameFruitsLink.swf
--------------------------------------------------------------------------------
/flash/gamePhysics.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/gamePhysics.fla
--------------------------------------------------------------------------------
/flash/gamePhysics.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/gamePhysics.swf
--------------------------------------------------------------------------------
/flash/gamePopStars.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/gamePopStars.fla
--------------------------------------------------------------------------------
/flash/gamePopStars.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/gamePopStars.swf
--------------------------------------------------------------------------------
/flash/gameShooters.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/gameShooters.fla
--------------------------------------------------------------------------------
/flash/gameShooters.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/gameShooters.swf
--------------------------------------------------------------------------------
/flash/gameTimberQiang.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/gameTimberQiang.fla
--------------------------------------------------------------------------------
/flash/gameTimberQiang.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/gameTimberQiang.swf
--------------------------------------------------------------------------------
/flash/monkeyRun.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/monkeyRun.fla
--------------------------------------------------------------------------------
/flash/monkeyRun.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/monkeyRun.swf
--------------------------------------------------------------------------------
/flash/sceneNav.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/sceneNav.fla
--------------------------------------------------------------------------------
/flash/sceneNav.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/sceneNav.swf
--------------------------------------------------------------------------------
/flash/scrollingBG.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/scrollingBG.fla
--------------------------------------------------------------------------------
/flash/scrollingBG.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/scrollingBG.swf
--------------------------------------------------------------------------------
/flash/skeletonControl.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/skeletonControl.fla
--------------------------------------------------------------------------------
/flash/skeletonControl.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/skeletonControl.swf
--------------------------------------------------------------------------------
/flash/tiledImage.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/tiledImage.fla
--------------------------------------------------------------------------------
/flash/tiledImage.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/tiledImage.swf
--------------------------------------------------------------------------------
/flash/uiBmFont.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/uiBmFont.fla
--------------------------------------------------------------------------------
/flash/uiBmFont.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/uiBmFont.swf
--------------------------------------------------------------------------------
/flash/uiButton.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/uiButton.fla
--------------------------------------------------------------------------------
/flash/uiButton.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/uiButton.swf
--------------------------------------------------------------------------------
/flash/uiInput.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/uiInput.fla
--------------------------------------------------------------------------------
/flash/uiInput.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/uiInput.swf
--------------------------------------------------------------------------------
/flash/uiPanel.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/uiPanel.fla
--------------------------------------------------------------------------------
/flash/uiPanel.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/uiPanel.swf
--------------------------------------------------------------------------------
/flash/uiProgress.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/uiProgress.fla
--------------------------------------------------------------------------------
/flash/uiProgress.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flash/uiProgress.swf
--------------------------------------------------------------------------------
/flax.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/flax.png
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Cocos2d-html5 Hello World test
6 |
7 |
8 |
9 |
10 |
11 |
12 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/main.js:
--------------------------------------------------------------------------------
1 | var currentSceneIndex = 0;
2 |
3 | cc.game.onStart = function(){
4 | //初始化引擎 (Initialize Flax)
5 | //第一个参数:分辨率模式 (First param: resolution policy)
6 | //第二个参数:初始化用户数据,可以在cookie里存储复杂的数据 (Second param: the initial user data saved with cookie)
7 | flax.init(cc.ResolutionPolicy.SHOW_ALL,{score:0, warningShowed:false});
8 |
9 | //根据config配置来注册场景 (Register all the scenes according by the Config.js)
10 | for(var i = 0; i < Global.scenesList.length; i++)
11 | {
12 | var s = Global.scenesList[i];
13 | //注册场景: 名字,场景,所需素材 (Register scene: scene name, scene class and the resources needed)
14 | flax.registerScene(s.name, s.class, s.res);
15 | }
16 |
17 | //根据url来获取GET参数 (Fetch the GET params by the url)
18 | var getVars = flax.getUrlVars();
19 | //从url中解析是否有通过lan指定当前语言,否则按照project.json中的language设置或者系统语言 (Param lan in url means current language)
20 | if(getVars['lan']) flax.updateLanguage(getVars['lan']);
21 | //根据参数sid,来显示第一个场景 (Param s in url means the initial scene index)
22 | currentSceneIndex = parseInt(getVars["sid"]) || 0;
23 | flax.replaceScene(Global.scenesList[currentSceneIndex].name);
24 |
25 | //Show the warning for a new user
26 | if(!flax.userData.warningShowed){
27 | var warning = "Warning: \n示例中所有的素材,只能作为学习目的使用,不得用于任何上线的游戏中,谢谢合作!\nAll the assets in this example, only can be used to research, is FORBIDDEN to any business project, thank you!";
28 | cc.sys.isNative? cc.log(warning) : alert(warning);
29 | flax.userData.warningShowed = true;
30 | flax.saveUserData();
31 | }
32 | };
33 | cc.game.run();
--------------------------------------------------------------------------------
/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "version":1.0,
3 | "gameId":"flaxDemo",
4 | "width":640,
5 | "height":880,
6 | "landscape":false,
7 | "rotateImg":"res/rotate.png",
8 | "language":"zh",
9 | "languageJson":true,
10 | "useFlaxRes":false,
11 | "loading":"res/logo.png",
12 | "preloader":"flax.Preloader",
13 | "domainAllowed":[
14 |
15 | ],
16 | "project_type":"javascript",
17 | "debugMode":1,
18 | "showFPS":true,
19 | "frameRate":60,
20 | "id":"gameCanvas",
21 | "renderMode":0,
22 | "engineDir":"../../cocos2d-js-v3.6.1/frameworks/cocos2d-html5",
23 | "modules":[
24 | "cocos2d",
25 | "box2d",
26 | "editbox"
27 | ],
28 | "jsList":[
29 | "src/flax/Flax.js",
30 | "src/flax/signal/SignalBinding.js",
31 | "src/flax/signal/Signal.js",
32 | "src/flax/signal/wrapper.js",
33 | "src/flax/core/DebugDraw.js",
34 | "src/flax/core/InputManager.js",
35 | "src/flax/core/FlaxLoader.js",
36 | "src/flax/core/AssetsManager.js",
37 | "src/flax/core/Physics.js",
38 | "src/flax/module/PhysicsModule.js",
39 | "src/flax/module/TileMapModule.js",
40 | "src/flax/module/ScreenLayoutModule.js",
41 | "src/flax/module/MoveModule.js",
42 | "src/flax/core/FlaxSprite.js",
43 | "src/flax/core/Animator.js",
44 | "src/flax/core/Image.js",
45 | "src/flax/core/MovieClip.js",
46 | "src/flax/core/ProgressBar.js",
47 | "src/flax/core/Label.js",
48 | "src/flax/core/Button.js",
49 | "src/flax/game/Preloader.js",
50 | "src/flax/game/TileMap.js",
51 | "src/flax/game/UserData.js",
52 | "src/flax/game/ObjectPool.js",
53 | "src/flax/module/HealthModule.js",
54 | "src/flax/module/EnemyWaveModule.js",
55 | "src/flax/game/SoundButton.js",
56 | "src/flax/game/Gun.js",
57 | "src/flax/game/Gunner.js",
58 | "src/flax/game/ScrollingBG.js",
59 | "src/flax/game/ScrollPane.js",
60 | "src/flax/game/TiledImage.js",
61 | "src/flax/game/LinkFinder.js",
62 | "src/flax/game/Color.js",
63 | "src/resource.js",
64 | "src/BaseScene.js",
65 | "src/AnimationAndAnchor.js",
66 | "src/SkeletonAndControl.js",
67 | "src/UIButton.js",
68 | "src/CustomClickTest.js",
69 | "src/UIProgress.js",
70 | "src/UIBMFont.js",
71 | "src/UIInput.js",
72 | "src/UIPanel.js",
73 | "src/EffectAndPool.js",
74 | "src/ScrollingBGTest.js",
75 | "src/TiledImageTest.js",
76 | "src/GamePopStars.js",
77 | "src/GameBubbles.js",
78 | "src/GameFruitsLink.js",
79 | "src/GameShooters.js",
80 | "src/GamePhysics.js",
81 | "src/GameTimberQiang.js",
82 | "src/Config.js"
83 | ]
84 |
85 | }
--------------------------------------------------------------------------------
/res/boss.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/boss.png
--------------------------------------------------------------------------------
/res/customClick.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/customClick.png
--------------------------------------------------------------------------------
/res/effect.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 | frames
4 |
5 | effect_000000
6 |
7 | frame
8 | {{260,180},{59,60}}
9 | offset
10 | {1.40,1.45}
11 | rotated
12 |
13 | sourceSize
14 | {258,265}
15 |
16 | effect_000001
17 |
18 | frame
19 | {{544,0},{85,90}}
20 | offset
21 | {1.40,-1.55}
22 | rotated
23 |
24 | sourceSize
25 | {258,265}
26 |
27 | effect_000002
28 |
29 | frame
30 | {{437,0},{107,113}}
31 | offset
32 | {1.40,-1.05}
33 | rotated
34 |
35 | sourceSize
36 | {258,265}
37 |
38 | effect_000003
39 |
40 | frame
41 | {{436,608},{110,113}}
42 | offset
43 | {2.90,-1.05}
44 | rotated
45 |
46 | sourceSize
47 | {258,265}
48 |
49 | effect_000004
50 |
51 | frame
52 | {{436,473},{129,135}}
53 | offset
54 | {1.40,-1.05}
55 | rotated
56 |
57 | sourceSize
58 | {258,265}
59 |
60 | effect_000005
61 |
62 | frame
63 | {{433,337},{141,136}}
64 | offset
65 | {3.40,-0.55}
66 | rotated
67 |
68 | sourceSize
69 | {258,265}
70 |
71 | effect_000006
72 |
73 | frame
74 | {{433,180},{160,157}}
75 | offset
76 | {2.90,-1.05}
77 | rotated
78 |
79 | sourceSize
80 | {258,265}
81 |
82 | effect_000007
83 |
84 | frame
85 | {{260,0},{177,180}}
86 | offset
87 | {2.40,-0.55}
88 | rotated
89 |
90 | sourceSize
91 | {258,265}
92 |
93 | effect_000008
94 |
95 | frame
96 | {{237,267},{196,202}}
97 | offset
98 | {0.90,-0.55}
99 | rotated
100 |
101 | sourceSize
102 | {258,265}
103 |
104 | effect_000009
105 |
106 | frame
107 | {{223,511},{213,215}}
108 | offset
109 | {-1.60,-3.05}
110 | rotated
111 |
112 | sourceSize
113 | {258,265}
114 |
115 | effect_000010
116 |
117 | frame
118 | {{0,511},{223,222}}
119 | offset
120 | {-3.60,-0.10}
121 | rotated
122 |
123 | sourceSize
124 | {258,265}
125 |
126 | effect_000011
127 |
128 | frame
129 | {{0,267},{237,244}}
130 | offset
131 | {-0.15,0.15}
132 | rotated
133 |
134 | sourceSize
135 | {258,265}
136 |
137 | effect_000012
138 |
139 | frame
140 | {{0,0},{260,267}}
141 | offset
142 | {0.00,0.00}
143 | rotated
144 |
145 | sourceSize
146 | {258,265}
147 |
148 |
149 | metadata
150 |
151 | flaxVersion
152 | 2.23
153 | fps
154 | 24
155 | format
156 | 2
157 | realTextureFileName
158 | effect.png
159 | size
160 | {660,768}
161 | textureFileName
162 | effect.png
163 |
164 | displays
165 |
166 | effect
167 |
168 | type
169 | null
170 | anchorX
171 | 0.51453
172 | anchorY
173 | 0.50094
174 | start
175 | 0
176 | end
177 | 12
178 |
179 |
180 |
181 |
--------------------------------------------------------------------------------
/res/effect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/effect.png
--------------------------------------------------------------------------------
/res/font/ANTSYPAN.TTF:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/font/ANTSYPAN.TTF
--------------------------------------------------------------------------------
/res/gameBubbles.b1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/gameBubbles.b1.jpg
--------------------------------------------------------------------------------
/res/gameBubbles.bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/gameBubbles.bg.jpg
--------------------------------------------------------------------------------
/res/gameBubbles.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 | frames
4 |
5 | gameBubbles_000000
6 |
7 | frame
8 | {{0,56},{56,56}}
9 | offset
10 | {0.00,0.00}
11 | rotated
12 |
13 | sourceSize
14 | {54,54}
15 |
16 | gameBubbles_000001
17 |
18 | frame
19 | {{56,0},{56,56}}
20 | offset
21 | {0.00,0.00}
22 | rotated
23 |
24 | sourceSize
25 | {54,54}
26 |
27 | gameBubbles_000002
28 |
29 | frame
30 | {{56,56},{56,56}}
31 | offset
32 | {0.00,0.00}
33 | rotated
34 |
35 | sourceSize
36 | {54,54}
37 |
38 | gameBubbles_000003
39 |
40 | frame
41 | {{0,0},{56,56}}
42 | offset
43 | {0.00,0.00}
44 | rotated
45 |
46 | sourceSize
47 | {54,54}
48 |
49 |
50 | metadata
51 |
52 | flaxVersion
53 | 2.23
54 | fps
55 | 24
56 | format
57 | 2
58 | realTextureFileName
59 | gameBubbles.png
60 | size
61 | {164,164}
62 | textureFileName
63 | gameBubbles.png
64 |
65 | displays
66 |
67 | b0
68 |
69 | type
70 | null
71 | anchorX
72 | 0.50463
73 | anchorY
74 | 0.50926
75 | start
76 | 0
77 | end
78 | 0
79 |
80 | b1
81 |
82 | type
83 | null
84 | anchorX
85 | 0.51389
86 | anchorY
87 | 0.50926
88 | start
89 | 1
90 | end
91 | 1
92 |
93 | b2
94 |
95 | type
96 | null
97 | anchorX
98 | 0.49167
99 | anchorY
100 | 0.50833
101 | start
102 | 2
103 | end
104 | 2
105 |
106 | b3
107 |
108 | type
109 | null
110 | anchorX
111 | 0.51389
112 | anchorY
113 | 0.50741
114 | start
115 | 3
116 | end
117 | 3
118 |
119 | bg
120 |
121 | type
122 | jpg
123 | anchorX
124 | 0.00039
125 | anchorY
126 | 0.04501
127 | url
128 | gameBubbles.bg.jpg
129 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/res/gameBubbles.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/gameBubbles.png
--------------------------------------------------------------------------------
/res/gameFruitsLink.bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/gameFruitsLink.bg.jpg
--------------------------------------------------------------------------------
/res/gameFruitsLink.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/gameFruitsLink.png
--------------------------------------------------------------------------------
/res/gamePhysics.bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/gamePhysics.bg.jpg
--------------------------------------------------------------------------------
/res/gamePhysics.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/gamePhysics.png
--------------------------------------------------------------------------------
/res/gamePopStars.bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/gamePopStars.bg.jpg
--------------------------------------------------------------------------------
/res/gamePopStars.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 | frames
4 |
5 | gamePopStars_000000
6 |
7 | frame
8 | {{0,0},{66,66}}
9 | offset
10 | {0.00,0.00}
11 | rotated
12 |
13 | sourceSize
14 | {64,64}
15 |
16 | gamePopStars_000001
17 |
18 | frame
19 | {{64,66},{64,64}}
20 | offset
21 | {0.00,0.00}
22 | rotated
23 |
24 | sourceSize
25 | {62,62}
26 |
27 | gamePopStars_000002
28 |
29 | frame
30 | {{0,195},{64,65}}
31 | offset
32 | {0.00,0.00}
33 | rotated
34 |
35 | sourceSize
36 | {62,63}
37 |
38 | gamePopStars_000003
39 |
40 | frame
41 | {{64,130},{64,64}}
42 | offset
43 | {0.00,0.00}
44 | rotated
45 |
46 | sourceSize
47 | {62,62}
48 |
49 | gamePopStars_000004
50 |
51 | frame
52 | {{0,131},{64,64}}
53 | offset
54 | {0.00,0.00}
55 | rotated
56 |
57 | sourceSize
58 | {62,62}
59 |
60 | gamePopStars_000005
61 |
62 | frame
63 | {{0,66},{64,65}}
64 | offset
65 | {0.00,0.00}
66 | rotated
67 |
68 | sourceSize
69 | {62,63}
70 |
71 |
72 | metadata
73 |
74 | flaxVersion
75 | 2.23
76 | fps
77 | 24
78 | format
79 | 2
80 | realTextureFileName
81 | gamePopStars.png
82 | size
83 | {166,266}
84 | textureFileName
85 | gamePopStars.png
86 |
87 | displays
88 |
89 | selectimg
90 |
91 | type
92 | null
93 | anchorX
94 | 0.50000
95 | anchorY
96 | 0.50000
97 | start
98 | 0
99 | end
100 | 0
101 |
102 | star0
103 |
104 | type
105 | null
106 | anchorX
107 | 0.50000
108 | anchorY
109 | 0.50000
110 | start
111 | 1
112 | end
113 | 1
114 |
115 | star1
116 |
117 | type
118 | null
119 | anchorX
120 | 0.50000
121 | anchorY
122 | 0.50794
123 | start
124 | 2
125 | end
126 | 2
127 |
128 | star2
129 |
130 | type
131 | null
132 | anchorX
133 | 0.50000
134 | anchorY
135 | 0.50000
136 | start
137 | 3
138 | end
139 | 3
140 |
141 | star3
142 |
143 | type
144 | null
145 | anchorX
146 | 0.50000
147 | anchorY
148 | 0.50000
149 | start
150 | 4
151 | end
152 | 4
153 |
154 | star4
155 |
156 | type
157 | null
158 | anchorX
159 | 0.50000
160 | anchorY
161 | 0.49206
162 | start
163 | 5
164 | end
165 | 5
166 |
167 | bg
168 |
169 | type
170 | jpg
171 | anchorX
172 | 0.00000
173 | anchorY
174 | 0.00000
175 | url
176 | gamePopStars.bg.jpg
177 |
178 |
179 |
180 |
--------------------------------------------------------------------------------
/res/gamePopStars.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/gamePopStars.png
--------------------------------------------------------------------------------
/res/gameShooters.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/gameShooters.png
--------------------------------------------------------------------------------
/res/gameTimberQiang.Symbol1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/gameTimberQiang.Symbol1.jpg
--------------------------------------------------------------------------------
/res/gameTimberQiang.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/gameTimberQiang.png
--------------------------------------------------------------------------------
/res/heros.bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/heros.bg.jpg
--------------------------------------------------------------------------------
/res/heros.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/heros.png
--------------------------------------------------------------------------------
/res/locale/en.json:
--------------------------------------------------------------------------------
1 | {
2 | "animClickTip":"Click the monkey to change its FPS",
3 | "animation":"Frame-by-frame animation and anchor",
4 | "skeleton":"Skeleton animation and control",
5 | "uiButton":"UI buttons",
6 | "Tab":"Tab",
7 | "startx":"Scroll X",
8 | "starty":"Scroll Y",
9 | "pause":"Pause",
10 | "resume":"Resume",
11 | "stop":"Stop",
12 | "reset":"Reset",
13 | "uiProgress":"UI progress bars",
14 | "bmp":"Bitmap Text",
15 | "uiBmFont":"Bitmap and TTF Text",
16 | "uiInput":"Input Text",
17 | "uiPanel":"A UI panel",
18 | "effect":"Effect and ObjectPool(Click Screen)",
19 | "poppingStars":"Popping Stars: TileMap",
20 | "bubbles":"Bubbles: TileMap",
21 | "fruitsLink":"FruitsLink: A game with 5 levels",
22 | "shooters":"Shooters: gun and shoot",
23 | "scrollingBG": "Scrolling BG",
24 | "tiledImage":"Tiled Image(Click Screen)",
25 | "physics":"Physics Game(Click Screen)",
26 | "timberQiangMenu":"A game: Timber Qiang",
27 | "timberQiangGame":"A game: Timber Qiang",
28 | "customClick":"Custom Click Area",
29 | "noCollider":"No Custom Click",
30 | "rectCollider":"Rectangle Click Area",
31 | "circleCollider":"Circle Click Area",
32 | "polyCollider":"Fully CusTOM Click Area"
33 | }
--------------------------------------------------------------------------------
/res/locale/zh.json:
--------------------------------------------------------------------------------
1 | {
2 | "animClickTip":"点击猴子来改变其FPS",
3 | "animation":"逐帧动画与锚点",
4 | "skeleton":"骨骼动画与控制",
5 | "uiButton":"UI 按钮",
6 | "Tab":"标签",
7 | "startx":"X向滚动",
8 | "starty":"Y向滚动",
9 | "pause":"暂停",
10 | "resume":"继续",
11 | "stop":"停止",
12 | "reset":"重置",
13 | "uiProgress":"UI 进度条",
14 | "bmp":"位图文本",
15 | "uiBmFont":"位图和TTF文本",
16 | "uiInput":"输入文本",
17 | "uiPanel":"一个UI面板",
18 | "effect":"特效和对象池(点屏幕)",
19 | "poppingStars":"消除星星: TileMap",
20 | "bubbles":"泡泡: TileMap",
21 | "fruitsLink":"水果连连看: 5关的小游戏",
22 | "shooters":"枪手: 枪与射击",
23 | "scrollingBG": "滚动背景",
24 | "tiledImage":"瓦片地图(点屏幕)",
25 | "physics":"物理游戏(点击屏幕)",
26 | "timberQiangMenu":"游戏:疯狂的光头强",
27 | "timberQiangGame":"游戏:疯狂的光头强",
28 | "customClick":"自定义点击区域",
29 | "noCollider":"不定义点击区域",
30 | "rectCollider":"矩形点击区域",
31 | "circleCollider":"圆形点击区域",
32 | "polyCollider":"任意形状点击区域"
33 | }
--------------------------------------------------------------------------------
/res/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/logo.png
--------------------------------------------------------------------------------
/res/monkeyRun.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 | frames
4 |
5 | monkeyRun_000000
6 |
7 | frame
8 | {{0,654},{78,90}}
9 | offset
10 | {0.00,0.00}
11 | rotated
12 |
13 | sourceSize
14 | {76,88}
15 |
16 | monkeyRun_000001
17 |
18 | frame
19 | {{0,0},{198,126}}
20 | offset
21 | {-16.00,-8.27}
22 | rotated
23 |
24 | sourceSize
25 | {228,142.05}
26 |
27 | monkeyRun_000002
28 |
29 | frame
30 | {{0,383},{193,133}}
31 | offset
32 | {-10.10,-5.52}
33 | rotated
34 |
35 | sourceSize
36 | {228,142.05}
37 |
38 | monkeyRun_000003
39 |
40 | frame
41 | {{192,516},{187,138}}
42 | offset
43 | {-4.65,-3.02}
44 | rotated
45 |
46 | sourceSize
47 | {228,142.05}
48 |
49 | monkeyRun_000004
50 |
51 | frame
52 | {{379,393},{181,144}}
53 | offset
54 | {2.85,0.03}
55 | rotated
56 |
57 | sourceSize
58 | {228,142.05}
59 |
60 | monkeyRun_000005
61 |
62 | frame
63 | {{198,0},{182,142}}
64 | offset
65 | {16.25,-0.12}
66 | rotated
67 |
68 | sourceSize
69 | {228,142.05}
70 |
71 | monkeyRun_000006
72 |
73 | frame
74 | {{558,139},{174,140}}
75 | offset
76 | {23.00,-2.02}
77 | rotated
78 |
79 | sourceSize
80 | {228,142.05}
81 |
82 | monkeyRun_000007
83 |
84 | frame
85 | {{379,537},{181,137}}
86 | offset
87 | {24.50,-3.32}
88 | rotated
89 |
90 | sourceSize
91 | {228,142.05}
92 |
93 | monkeyRun_000008
94 |
95 | frame
96 | {{381,139},{177,136}}
97 | offset
98 | {24.20,-3.52}
99 | rotated
100 |
101 | sourceSize
102 | {228,142.05}
103 |
104 | monkeyRun_000009
105 |
106 | frame
107 | {{380,0},{179,139}}
108 | offset
109 | {13.50,-2.47}
110 | rotated
111 |
112 | sourceSize
113 | {228,142.05}
114 |
115 | monkeyRun_000010
116 |
117 | frame
118 | {{195,251},{186,142}}
119 | offset
120 | {1.55,-0.97}
121 | rotated
122 |
123 | sourceSize
124 | {228,142.05}
125 |
126 | monkeyRun_000011
127 |
128 | frame
129 | {{0,516},{192,138}}
130 | offset
131 | {-4.80,-2.12}
132 | rotated
133 |
134 | sourceSize
135 | {228,142.05}
136 |
137 | monkeyRun_000012
138 |
139 | frame
140 | {{0,251},{195,132}}
141 | offset
142 | {-10.10,-5.92}
143 | rotated
144 |
145 | sourceSize
146 | {228,142.05}
147 |
148 | monkeyRun_000013
149 |
150 | frame
151 | {{0,126},{196,125}}
152 | offset
153 | {-14.30,-8.57}
154 | rotated
155 |
156 | sourceSize
157 | {228,142.05}
158 |
159 |
160 | metadata
161 |
162 | flaxVersion
163 | 2.23
164 | fps
165 | 24
166 | format
167 | 2
168 | realTextureFileName
169 | monkeyRun.png
170 | size
171 | {830,744}
172 | textureFileName
173 | monkeyRun.png
174 |
175 | displays
176 |
177 | anotherHead
178 |
179 | type
180 | null
181 | anchorX
182 | -1.90000
183 | anchorY
184 | -0.81364
185 | start
186 | 0
187 | end
188 | 0
189 |
190 | monkey_run
191 |
192 | type
193 | null
194 | anchorX
195 | 0.55154
196 | anchorY
197 | 0.13552
198 | start
199 | 1
200 | end
201 | 13
202 |
203 |
204 | mcs
205 |
206 | ui
207 |
208 | type
209 | null
210 | totalFrames
211 | 1
212 | rect
213 | 0,0,568.95,770.75
214 | anchorX
215 | 0.00000
216 | anchorY
217 | 0.00130
218 | children
219 |
220 | fpsTxt
221 |
222 | class
223 | null
224 | zIndex
225 | 0
226 | frames
227 | 220.00,770.75,0.00,1.00000,1.00000,1.00,0,0.00,0.00,Arial,32,#F4DC95,center,235,40
228 | text
229 | FPS:
230 | input
231 |
232 |
233 | tipTxt
234 |
235 | class
236 | animClickTip
237 | zIndex
238 | 1
239 | frames
240 | 70.00,190.75,0.00,1.00000,1.00000,1.00,1,0.00,0.00,Arial,28,#F4DC95,center,499,35
241 | text
242 | tips
243 | input
244 |
245 |
246 |
247 |
248 |
249 |
250 |
--------------------------------------------------------------------------------
/res/monkeyRun.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/monkeyRun.png
--------------------------------------------------------------------------------
/res/music/bg.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/music/bg.mp3
--------------------------------------------------------------------------------
/res/music/chop.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/music/chop.mp3
--------------------------------------------------------------------------------
/res/music/gun0.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/music/gun0.mp3
--------------------------------------------------------------------------------
/res/music/gun1.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/music/gun1.mp3
--------------------------------------------------------------------------------
/res/music/monkey0.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/music/monkey0.mp3
--------------------------------------------------------------------------------
/res/music/monkey1.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/music/monkey1.mp3
--------------------------------------------------------------------------------
/res/music/scream.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/music/scream.wav
--------------------------------------------------------------------------------
/res/physics.bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/physics.bg.jpg
--------------------------------------------------------------------------------
/res/physics.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/physics.png
--------------------------------------------------------------------------------
/res/rotate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/rotate.png
--------------------------------------------------------------------------------
/res/sceneNav.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/sceneNav.png
--------------------------------------------------------------------------------
/res/scrollingBG.bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/scrollingBG.bg.jpg
--------------------------------------------------------------------------------
/res/scrollingBG.bg0.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/scrollingBG.bg0.jpg
--------------------------------------------------------------------------------
/res/scrollingBG.bg1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/scrollingBG.bg1.jpg
--------------------------------------------------------------------------------
/res/scrollingBG.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 | frames
4 |
5 | scrollingBG_000000
6 |
7 | frame
8 | {{0,0},{62,43}}
9 | offset
10 | {0.00,0.00}
11 | rotated
12 |
13 | sourceSize
14 | {60,41}
15 |
16 |
17 | metadata
18 |
19 | flaxVersion
20 | 2.3
21 | fps
22 | 24
23 | format
24 | 2
25 | realTextureFileName
26 | scrollingBG.png
27 | size
28 | {64,64}
29 | textureFileName
30 | scrollingBG.png
31 |
32 | displays
33 |
34 | asset3
35 |
36 | type
37 | null
38 | anchorX
39 | 0.26333
40 | anchorY
41 | 0.54146
42 | start
43 | 0
44 | end
45 | 0
46 |
47 | bg
48 |
49 | type
50 | jpg
51 | anchorX
52 | 0.00000
53 | anchorY
54 | 0.00000
55 | url
56 | scrollingBG.bg.jpg
57 |
58 | bg0
59 |
60 | type
61 | jpg
62 | anchorX
63 | 0.00000
64 | anchorY
65 | 0.00000
66 | url
67 | scrollingBG.bg0.jpg
68 |
69 | bg1
70 |
71 | type
72 | jpg
73 | anchorX
74 | 0.00000
75 | anchorY
76 | 0.00000
77 | url
78 | scrollingBG.bg1.jpg
79 |
80 |
81 | mcs
82 |
83 | mcBtn
84 |
85 | type
86 | button
87 | totalFrames
88 | 1
89 | rect
90 | 0,0,70.00,45.25
91 | anchorX
92 | 0.62429
93 | anchorY
94 | 0.51602
95 | children
96 |
97 | label
98 |
99 | class
100 | null
101 | zIndex
102 | 1
103 | frames
104 | 6.75,37.35,0.00,1.00000,1.00000,1.00,1,0.00,0.00,Arial,14,#F4DC95,center,58,30
105 | text
106 | Button
107 | input
108 |
109 |
110 | instance2943
111 |
112 | class
113 | asset3
114 | zIndex
115 | 0
116 | frames
117 | 20.60,20.85,0.00,1.30356,1.30029,1.00,0,0.00,0.00
118 |
119 |
120 |
121 | ui
122 |
123 | type
124 | null
125 | totalFrames
126 | 1
127 | rect
128 | 0,0,640.00,961.00
129 | anchorX
130 | 0.00000
131 | anchorY
132 | 0.00104
133 | children
134 |
135 | bg
136 |
137 | class
138 | bg
139 | zIndex
140 | 0
141 | frames
142 | 0.00,1.00,0.00,1.00000,1.00000,1.00,0,0.00,0.00
143 |
144 | startyBtn
145 |
146 | class
147 | mcBtn
148 | zIndex
149 | 2
150 | frames
151 | 327.65,792.25,0.00,1.00000,1.00000,1.00,2,0.00,0.00
152 |
153 | resumeBtn
154 |
155 | class
156 | mcBtn
157 | zIndex
158 | 4
159 | frames
160 | 482.65,792.25,0.00,1.00000,1.00000,1.00,4,0.00,0.00
161 |
162 | startxBtn
163 |
164 | class
165 | mcBtn
166 | zIndex
167 | 1
168 | frames
169 | 248.65,792.25,0.00,1.00000,1.00000,1.00,1,0.00,0.00
170 |
171 | resetBtn
172 |
173 | class
174 | mcBtn
175 | zIndex
176 | 5
177 | frames
178 | 168.65,792.25,0.00,1.00000,1.00000,1.00,5,0.00,0.00
179 |
180 | pauseBtn
181 |
182 | class
183 | mcBtn
184 | zIndex
185 | 3
186 | frames
187 | 404.65,792.25,0.00,1.00000,1.00000,1.00,3,0.00,0.00
188 |
189 |
190 |
191 |
192 |
193 |
--------------------------------------------------------------------------------
/res/scrollingBG.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/scrollingBG.png
--------------------------------------------------------------------------------
/res/skeletonControl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/skeletonControl.png
--------------------------------------------------------------------------------
/res/tiledImage.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 | frames
4 |
5 | tiledImage_000000
6 |
7 | frame
8 | {{95,95},{95,95}}
9 | offset
10 | {0.00,0.00}
11 | rotated
12 |
13 | sourceSize
14 | {93,93}
15 |
16 | tiledImage_000001
17 |
18 | frame
19 | {{95,0},{95,95}}
20 | offset
21 | {0.00,0.00}
22 | rotated
23 |
24 | sourceSize
25 | {93,93}
26 |
27 | tiledImage_000002
28 |
29 | frame
30 | {{95,190},{95,95}}
31 | offset
32 | {0.00,0.00}
33 | rotated
34 |
35 | sourceSize
36 | {93,93}
37 |
38 | tiledImage_000003
39 |
40 | frame
41 | {{0,95},{95,95}}
42 | offset
43 | {0.00,0.00}
44 | rotated
45 |
46 | sourceSize
47 | {93,93}
48 |
49 | tiledImage_000004
50 |
51 | frame
52 | {{0,190},{95,95}}
53 | offset
54 | {0.00,0.00}
55 | rotated
56 |
57 | sourceSize
58 | {93,93}
59 |
60 | tiledImage_000005
61 |
62 | frame
63 | {{0,0},{95,95}}
64 | offset
65 | {0.00,0.00}
66 | rotated
67 |
68 | sourceSize
69 | {93,93}
70 |
71 |
72 | metadata
73 |
74 | flaxVersion
75 | 2.23
76 | fps
77 | 24
78 | format
79 | 2
80 | realTextureFileName
81 | tiledImage.png
82 | size
83 | {196,296}
84 | textureFileName
85 | tiledImage.png
86 |
87 | displays
88 |
89 | tile0
90 |
91 | type
92 | null
93 | anchorX
94 | 0.50484
95 | anchorY
96 | 0.49677
97 | start
98 | 0
99 | end
100 | 4
101 |
102 | tile1
103 |
104 | type
105 | null
106 | anchorX
107 | 0.50484
108 | anchorY
109 | 0.49677
110 | start
111 | 5
112 | end
113 | 5
114 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/res/tiledImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/tiledImage.png
--------------------------------------------------------------------------------
/res/uiBmFont.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/uiBmFont.png
--------------------------------------------------------------------------------
/res/uiButton.asset1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/uiButton.asset1.png
--------------------------------------------------------------------------------
/res/uiButton.asset3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/uiButton.asset3.png
--------------------------------------------------------------------------------
/res/uiButton.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/uiButton.png
--------------------------------------------------------------------------------
/res/uiInput.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/uiInput.png
--------------------------------------------------------------------------------
/res/uiPanel.PanelBack.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/uiPanel.PanelBack.jpg
--------------------------------------------------------------------------------
/res/uiPanel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/uiPanel.png
--------------------------------------------------------------------------------
/res/uiProgress.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/longyangxi/Flax-js-examples/a5093435df8dccee4bea4081c64eaa0089110a2a/res/uiProgress.png
--------------------------------------------------------------------------------
/src/AnimationAndAnchor.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-10.
3 | */
4 |
5 | var AnimationWithAnchor = BaseScene.extend({
6 | onEnter:function(){
7 | this._super();
8 | var anim = flax.assetsManager.createDisplay(res.animation, "monkey_run", {parent: this, x: cc.visibleRect.center.x, y: cc.visibleRect.center.y});
9 | anim.play();
10 |
11 | var ui = flax.assetsManager.createDisplay(res.animation, "ui", {parent: this});
12 | //默认情况下,动画的fps和fla里的设置是一样的
13 | //In default, an animation's fps is the same as the settings in the fla
14 | ui["fpsTxt"].text = "FPS: " + anim.fps;
15 |
16 | flax.inputManager.addListener(anim, function(){
17 | var fps = anim.fps + 12;
18 | if(fps > 60) fps = 24;
19 | anim.fps = fps;
20 | ui["fpsTxt"].text = "FPS: " + fps;
21 | });
22 | }
23 | })
--------------------------------------------------------------------------------
/src/BaseScene.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-10.
3 | */
4 |
5 | /**
6 | * 所有测试场景的基类
7 | * The base class of all the test scene
8 | * */
9 | var BaseScene = cc.Scene.extend({
10 | onEnter:function()
11 | {
12 | this._super();
13 | // flax.createBGLayer(this, cc.color(102, 102, 102));
14 | flax.createBGLayer(this, cc.color(51, 51, 51));
15 |
16 | var nav = flax.assetsManager.createDisplay(res.sceneNav, "SceneNav", {parent: this, zIndex: 9999});
17 | //场景导航按钮事件
18 | //Navigation button event
19 | flax.inputManager.addListener(nav["leftBtn"], this._showPrevScene, InputType.click, this);
20 | flax.inputManager.addListener(nav["rightBtn"], this._showNextScene, InputType.click, this);
21 |
22 | //侦听按键事件
23 | //Listening the keyboard event
24 | flax.inputManager.addListener(this, this._onKeyDown, InputType.keyPress);
25 |
26 | var info = Global.scenesList[currentSceneIndex];
27 | nav["navTxt"].text = (currentSceneIndex + 1) + "/" + Global.scenesList.length;
28 | nav["titleTxt"].text = flax.getLanguageStr(info.name);
29 |
30 | flax.inputManager.addListener(nav["logoBtn"], function(touch, event){
31 | flax.goHomeUrl();
32 | });
33 | },
34 | _showPrevScene:function()
35 | {
36 | currentSceneIndex--;
37 | if(currentSceneIndex < 0) {
38 | currentSceneIndex = 0;
39 | return;
40 | }
41 | var newScene = Global.scenesList[currentSceneIndex].name;
42 | //ignore physics demo in JSB
43 | if(cc.sys.isNative && newScene == "physics") this._showPrevScene();
44 | //todo, transiontion moves the scene then cause TileMap bug in JSB
45 | else flax.replaceScene(newScene);//, cc.TransitionMoveInB, 0.3);
46 | },
47 | _showNextScene:function()
48 | {
49 | currentSceneIndex++;
50 | if(currentSceneIndex > Global.scenesList.length - 1) {
51 | currentSceneIndex = Global.scenesList.length - 1;
52 | return;
53 | }
54 | var newScene = Global.scenesList[currentSceneIndex].name;
55 | //ignore physics demo in JSB
56 | if(cc.sys.isNative && newScene == "physics") this._showNextScene();
57 | //todo, transiontion moves the scene then cause TileMap bug in JSB
58 | else flax.replaceScene(newScene);//, cc.TransitionMoveInB, 0.3);
59 | },
60 | _onKeyDown:function(key)
61 | {
62 | if(key == "left") this._showPrevScene();
63 | else if(key == "right") this._showNextScene();
64 | }
65 | })
66 | /**
67 | * 特别注意:这里是Flax里资源到js类的动态映射,sceneNav.fla里有一个mc.TopBar的容器,创建时会优先寻找是否有一个js类叫TopBar,
68 | * 并继承于flax.MovieClip,有则动态映射过去,如果是逐帧动画,则应继承于flax.Animation
69 | *
70 | * Attention: Here we use the dynamic mapping in Flax, there is a container of mc.TopBar in sceneNav.fla, Flax will find if
71 | * there has a js class named TopBar and extends from flax.MovieClip when create this asset, if has, dynamic map to it. Of
72 | * course, if it's frame-by-frame animation, it should extend from flax.Animation
73 | *
74 | * Detail: http://flax.so/?p=196
75 | * */
76 | var TopBar = flax.MovieClip.extend({
77 | onEnter:function()
78 | {
79 | this._super();
80 | //初始化暂停按钮和声音按钮
81 | //Initial the pause button and the sound button
82 | this["pauseBtn"].selected = true;
83 | this["soundBtn"].selected = !flax.getSoundEnabled();
84 | //侦听暂停和声音按钮事件
85 | //Listening the pause and sound button click event
86 | flax.inputManager.addListener(this["pauseBtn"], this._onPauseChange, InputType.click, this);
87 | flax.inputManager.addListener(this["soundBtn"], this._onSoundChange, InputType.click, this);
88 | //多语言切换按钮事件
89 | //Language switch button event
90 | flax.inputManager.addListener(this["zhBtn"], this._updateLanguage);
91 | flax.inputManager.addListener(this["enBtn"], this._updateLanguage);
92 | },
93 | _onPauseChange:function(touch, event)
94 | {
95 | //选取状态则暂停游戏
96 | //Pause the game if the pauseBtn is selected
97 | if(!this["pauseBtn"].selected){
98 | //暂停游戏
99 | //Pause the game
100 | cc.director.pause();
101 | //弹出暂停面板
102 | //Popup a cover of pause
103 | var cover = flax.assetsManager.createDisplay(res.sceneNav, "PauseCover", {parent:flax.currentScene, zIndex:99999});
104 | //将面板作为遮挡层加入到inputManager,遮挡层以下的按钮事件将被屏蔽
105 | //Add the cover as a mask to the inputManager, the click event under the cover will be disabled
106 | flax.inputManager.addMask(cover);
107 | //点击cover的继续按钮,则游戏继续
108 | //Click the resumeBtn in the cover to resume the game
109 | flax.inputManager.addListener(cover["resumeBtn"], function(){
110 | //销毁cover
111 | //Destroy the cover
112 | cover.destroy();
113 | //继续游戏
114 | //Resume the game
115 | cc.director.resume();
116 | //恢复按钮状态
117 | //Recover the state of the pauseBtn
118 | this["pauseBtn"].selected = true;
119 | },InputType.click, this);
120 | }
121 | },
122 | _onSoundChange:function(touch, event)
123 | {
124 | //根据声音按钮是否选取状态来开关游戏声音
125 | //Enable or disable the game sound according to the sound button state,
126 | flax.setSoundEnabled(!this["soundBtn"].selected);
127 | },
128 | /**
129 | * 更新当前语言, 语言的配置在res/locale的json中
130 | * Update the current language, the language config json is in res/locale
131 | * */
132 | _updateLanguage:function(touch, event)
133 | {
134 | var lanBtn = event.currentTarget;
135 | if(lanBtn.name == "zhBtn"){
136 | flax.updateLanguage("zh");
137 | }else{
138 | flax.updateLanguage("en");
139 | }
140 | flax.refreshScene();
141 | }
142 | })
143 | //Avoid TopBar to be obscured in advanced compiled mode
144 | window['TopBar'] = TopBar;
--------------------------------------------------------------------------------
/src/Config.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-11.
3 | */
4 |
5 | var Global = Global || {};
6 |
7 | Global.scenesList = [
8 | //动画和锚点
9 | //Animation and the anchor
10 | {name:"animation", class:AnimationWithAnchor, res:res_animation},
11 | //骨骼动画与控制
12 | //Skeleton and the animation control
13 | {name:"skeleton", class:SkeletonAndControl, res:res_skeleton},
14 | //按钮
15 | //Button
16 | {name:"uiButton", class:UIButton, res:res_button},
17 | //自定义点击范围
18 | //Custom Click Area
19 | {name:"customClick", class:CustomClickTest, res:res_customClick},
20 | //进度条
21 | //ProgressBar
22 | {name:"uiProgress", class:UIProgress, res:res_progress},
23 | //位图字体
24 | //Bitmap Font
25 | {name:"uiBmFont", class:UIBmFont, res:res_uiBmFont},
26 | //输入文本
27 | //Input Text
28 | {name:"uiInput", class:UIInput, res:res_uiInput},
29 | //UI面板
30 | //UI panel
31 | {name:"uiPanel", class:UIPanelScene, res:res_uiPanel},
32 | //特效
33 | //effect
34 | {name:"effect", class:EffectAndPool, res:res_effect},
35 | //滚动背景
36 | //scroling BG
37 | {name:"scrollingBG", class: ScrollingBGTest, res:res_scrollingBG},
38 | //瓦片地图
39 | //Tiled Image
40 | {name:"tiledImage", class:TiledImageTest, res:res_tiledImage},
41 | //消除星星游戏
42 | //A simple game of popping stars
43 | {name:"poppingStars", class:GamePopStars, res:res_poppingStars},
44 | //泡泡游戏
45 | //A simple game of bubbles
46 | {name:"bubbles", class: GameBubbles, res:res_bubbles},
47 | //水果连连看
48 | //A simple game of fruits link
49 | {name:"fruitsLink", class: GameFruitsLink, res: res_fruitsLink},
50 | //射击
51 | //A simple game of shooters
52 | {name:"shooters", class: GameShooters, res: res_shooters},
53 | //物理游戏
54 | //A simple game of physics
55 | {name:"physics", class: GamePhysics, res: res_physics},
56 | //光头强砍树游戏
57 | //A simple game of timber qiang
58 | {name:"timberQiangMenu", class:MenuScene, res:res_timberQiang},
59 | {name:"timberQiangGame", class:GameScene}
60 | ];
--------------------------------------------------------------------------------
/src/CustomClickTest.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-3-18.
3 | */
4 |
5 | var CustomClickTest = BaseScene.extend({
6 | p:null,
7 | onEnter:function()
8 | {
9 | this._super();
10 | this.p = flax.assetsManager.createDisplay(res.customClick, "panel", {parent:this});
11 | this.p['infoTxt'].text = "";
12 | for(var i = 0; i < 4; i++)
13 | {
14 | var m = this.p["m" + i]
15 | m.mainCollider.debugDraw();
16 | flax.inputManager.addListener(m, this._onClick, null, this);
17 | }
18 | },
19 | _onClick:function(touch, event)
20 | {
21 | var target = event.currentTarget;
22 | this.p['infoTxt'].text = target.name + " was clicked!";
23 | this.scheduleOnce(function(){
24 | this.p['infoTxt'].text = "";
25 | }, 1.0);
26 | }
27 | })
--------------------------------------------------------------------------------
/src/EffectAndPool.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-14.
3 | */
4 | var EffectAndPool = BaseScene.extend({
5 | onEnter:function()
6 | {
7 | this._super();
8 | //一般情况下,flax会在首次使用某个素材时自动解析,但对于稍大的素材,如果能预先处理,可避免第一次使用该素材可能造成的卡顿
9 | //Flax always auto parse an asset when used at the first time. But for some large size of asset, if we handled it in advance,
10 | //the game will run more smoothly when the asset is used at the first time
11 | flax.assetsManager.addAssets(res.effect);
12 | //侦听鼠标或者触摸
13 | //Listening the mouse or touch
14 | //第一个target参数为null,表示点击屏幕任何地方均可触发
15 | //The first param(target) is null, means clicking anywhere of the screen will trigger the event
16 | flax.inputManager.addListener(null, this._onClick);
17 | },
18 | _onClick:function(touch, event)
19 | {
20 | var pos = touch.getLocation();
21 | //autoDestroyWhenOver = true, 表示动画播放完毕自动销毁
22 | //means the animation will auto destroyed after played
23 | //第四个参数为true, 表示动画将由对象池来处理
24 | //The forth param(fromPool) = true, means the animation will handled by the ObjectPool
25 | var effect = flax.assetsManager.createDisplay(res.effect, "effect", {parent:this,x:pos.x, y:pos.y, autoDestroyWhenOver:true},true);
26 | effect.gotoAndPlay(0);
27 | }
28 | })
--------------------------------------------------------------------------------
/src/GameBubbles.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-14.
3 | */
4 |
5 | var GameBubbles = BaseScene.extend({
6 | tileMap:null,
7 | blanks:null,
8 | onEnter:function()
9 | {
10 | this._super();
11 |
12 | var bg = flax.assetsManager.createDisplay(res.bubbles, "bg", {parent:this});
13 | flax.inputManager.addListener(bg, this.onClick, InputType.press, this);
14 |
15 | //create a new TileMap
16 | this.tileMap = new flax.TileMap();
17 | this.tileMap.isHexagon = true;
18 | this.tileMap.init(52, 48);
19 | this.tileMap.setMapSize(10, 12);
20 | this.tileMap.setPosition(56, 180);
21 |
22 | //Initialize the whole map
23 | for(var i = 0; i < this.tileMap.mapSize.width; i++)
24 | {
25 | for(var j = 0; j < this.tileMap.mapSize.height; j++)
26 | {
27 | var bubble = flax.assetsManager.createDisplay(res.bubbles, "b" + flax.randInt(0, 4), {parent: this}, true);
28 | this.tileMap.snapToTile(bubble, i, j, true);
29 | }
30 | }
31 | },
32 | onClick:function(touch, event)
33 | {
34 | var pos = touch.getLocation();
35 | var objs = this.tileMap.getObjects1(pos.x, pos.y);
36 | if(objs.length){
37 | var bubble = objs[0];
38 | //In scaling, dont handle
39 | if(bubble.scaleX < 1.0) return;
40 | var bubbles = this.tileMap.findConnectedObjects(bubble, "assetID");
41 | if(bubbles.length >= 2){
42 | //Destory all the bubbles with the same assetID(color)
43 | bubbles.push(bubble);
44 | this.blanks = [];
45 | for(var i = 0; i < bubbles.length; i++){
46 | bubble = bubbles[i];
47 | this.blanks.push(bubble.getPosition());
48 | bubble.destroy();
49 | }
50 | this.scheduleOnce(this.reGenerate, 0.1);
51 | }
52 | }
53 | },
54 | reGenerate:function()
55 | {
56 | for(var i = 0; i < this.blanks.length; i++)
57 | {
58 | var pos = this.blanks[i];
59 | var newBubble = flax.assetsManager.createDisplay(res.bubbles, "b" + flax.randInt(0, 4), {parent: this, scaleX: 0.3 + Math.random()*0.2, scaleY: 0.3 + Math.random()*0.2}, true);
60 | newBubble.tileMap = this.tileMap;
61 | newBubble.setPosition(pos);
62 | newBubble.runAction(cc.scaleTo(0.1, 1.0, 1.0));
63 | }
64 | }
65 | })
--------------------------------------------------------------------------------
/src/GameFruitsLink.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-15.
3 | */
4 | var LINK_WEIGHT = 2;
5 | var LINK_COLOR = cc.color(255, 255, 255, 200);
6 | var MAX_LEVEL = 5;
7 | var fruitsMap = null;
8 |
9 | var GameFruitsLink = BaseScene.extend({
10 | level:0,
11 | levelTime:60,
12 | timeLeft:0,
13 | totalFruits:0,
14 | panel:null,
15 | levelMap:null,
16 | onEnter:function()
17 | {
18 | this._super();
19 |
20 | this.panel = flax.assetsManager.createDisplay(res.fruits, "FruitsScene", {parent:this});
21 | this.panel['scoreTxt'].gap = - 3;
22 | this.panel['scoreTxt'].text = 0;
23 | this.panel['timeBar'].percentage = 100;
24 |
25 | this.timeLeft = this.levelTime;
26 | this.schedule(this.countDown, 1, cc.REPEAT_FOREVER, 1);
27 |
28 | fruitsMap = new flax.TileMap();
29 | fruitsMap.init(64, 64);
30 | fruitsMap.setMapSize(10,10);
31 | fruitsMap.setPositionY(64);
32 | // fruitsMap.showDebugGrid();
33 | this.newLevel();
34 | },
35 | countDown:function()
36 | {
37 | this.timeLeft--;
38 | if(this.timeLeft < 0){
39 | this.timeLeft = 0;
40 | this.unschedule(this.countDown);
41 | //todo,game over
42 | cc.log("Time is up, game over!");
43 | }
44 | this.panel['timeBar'].percentage = 100*this.timeLeft/this.levelTime;
45 | },
46 | newLevel:function()
47 | {
48 | this.level++;
49 | if(this.level > MAX_LEVEL) this.level = 1;
50 |
51 | if(this.levelMap){
52 | flax.inputManager.removeListener(this.panel['shuffleBtn'], this.levelMap.shuffle);
53 | flax.inputManager.removeListener(this.panel['findBtn'], this.levelMap.showHint);
54 | this.levelMap.destroy();
55 | }
56 | this.levelMap = flax.assetsManager.createDisplay(res.fruits, "level" + this.level, {parent: this});
57 | this.totalFruits = fruitsMap.getAllObjects().length;
58 |
59 | flax.inputManager.addListener(this.panel['shuffleBtn'], this.levelMap.shuffle, InputType.click, this.levelMap);
60 | flax.inputManager.addListener(this.panel['findBtn'], this.levelMap.showHint, InputType.click, this.levelMap);
61 |
62 | this.levelMap.onLinked.add(this.onLinked, this);
63 | },
64 | onLinked:function()
65 | {
66 | this.totalFruits -= 2;
67 | //Update the score
68 | this.panel['scoreTxt'].text = parseInt(this.panel['scoreTxt'].text) + 20;
69 | //Completed the level
70 | if(this.totalFruits == 0){
71 | var levelUp = flax.assetsManager.createDisplay(res.fruits, "LevelUpAnim", {parent:this, autoDestroyWhenOver:true}, true);
72 | levelUp.play();
73 | levelUp.setPosition(cc.visibleRect.center);
74 | levelUp.onAnimationOver.add(this.newLevel, this);
75 | }
76 | }
77 | })
78 |
79 | var LevelMap = flax.MovieClip.extend({
80 | onLinked:null,
81 | firstFruit:null,
82 | clickRect:null,
83 | _linkCanvas:null,
84 | onEnter:function()
85 | {
86 | this._super();
87 | LinkFinder.map = fruitsMap;
88 | for(var i = 0; i < this.getChildrenCount(); i++)
89 | {
90 | fruitsMap.snapToTile(this.children[i], null, null, true);
91 | }
92 | flax.inputManager.addListener(null, this.onClick, InputType.click, this);
93 |
94 | this._linkCanvas = new cc.DrawNode();
95 | this.addChild(this._linkCanvas, 9999);
96 | this.onLinked = new signals.Signal();
97 | },
98 | onExit:function()
99 | {
100 | this._super();
101 | flax.inputManager.removeListener(null, this.onClick);
102 | this.onLinked.removeAll();
103 | },
104 | onClick:function(touch, event)
105 | {
106 | var pos = touch.getLocation();
107 | var objs = fruitsMap.getObjects1(pos.x, pos.y);
108 | if(!objs.length) return;
109 | if(this.firstFruit == null){
110 | this.firstFruit = objs[0];
111 | //Show the hint animation
112 | this.clickRect = flax.assetsManager.createDisplay(res.fruits, "RectAnim", {parent:this, x: this.firstFruit.x, y: this.firstFruit.y, zIndex:999999},true);
113 | this.clickRect.play();
114 | }else{
115 | var secondFruit = objs[0];
116 | //Try to find the link between the two fruits
117 | var link = LinkFinder.findLink(this.firstFruit.tx, this.firstFruit.ty, secondFruit.tx, secondFruit.ty);
118 | //The link is valid and the assetID is the same, which means it's linkable
119 | if(link && this.firstFruit.assetID == secondFruit.assetID){
120 | //Remove the fruits from the tileMap
121 | this.firstFruit.tileMap = secondFruit.tileMap = null;
122 | //show the linked path
123 | this._showLinkedPath(link);
124 | //destroy the fruits
125 | this.firstFruit.destroy();
126 | secondFruit.destroy();
127 | //reset
128 | this.firstFruit = null;
129 | this.clickRect.destroy();
130 | this.clickRect = null;
131 | //dispatch the signal
132 | this.onLinked.dispatch()
133 | }else{
134 | //link failed, move the hint anim to the new start fruit
135 | this.firstFruit = secondFruit;
136 | this.clickRect.runAction(cc.moveTo(0.2, secondFruit.x, secondFruit.y));
137 | }
138 | }
139 | },
140 | /**
141 | * Show linked path
142 | * */
143 | _showLinkedPath:function(link)
144 | {
145 | for(var i = 1; i <= link.length - 1; i++)
146 | {
147 | var tile0 = link[i - 1];
148 | var tile1 = link[i];
149 | this._linkCanvas.drawSegment(fruitsMap.getTiledPosition(tile0.x, tile0.y),fruitsMap.getTiledPosition(tile1.x, tile1.y),LINK_WEIGHT,LINK_COLOR);
150 | }
151 | this.scheduleOnce(function(){
152 | this._linkCanvas.clear();
153 | }, 0.3);
154 | },
155 | shuffle:function()
156 | {
157 | LinkFinder.shuffle();
158 | if(this.clickRect){
159 | this.clickRect.destroy();
160 | this.clickRect = null;
161 | }
162 | this.firstFruit = null;
163 | },
164 | /**
165 | * Show linkable pair of fruits
166 | * */
167 | showHint:function()
168 | {
169 | var pair = LinkFinder.findAvailableLink();
170 | if(!pair) return;
171 | var fruit0 = pair[0];
172 | var fruit1 = pair[1];
173 | if(fruit0 && fruit0){
174 | var act0 = cc.RepeatForever.create(cc.Sequence.create(cc.FadeOut.create(0.2), cc.FadeIn.create(0.3)));
175 | fruit0.runAction(act0);
176 | var act1 = cc.RepeatForever.create(cc.Sequence.create(cc.FadeOut.create(0.2), cc.FadeIn.create(0.3)));
177 | fruit1.runAction(act1);
178 | }
179 | }
180 | })
181 | //Avoid LevelMap to be obscured in advanced compiled mode
182 | window['LevelMap'] = LevelMap;
--------------------------------------------------------------------------------
/src/GamePhysics.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-24.
3 | */
4 | var theGravity = {x:0, y:-35};
5 | var GamePhysics = BaseScene.extend({
6 | ui:null,
7 | gun:null,
8 | onEnter:function()
9 | {
10 | this._super();
11 | this.ui = flax.assetsManager.createDisplay(res.physics, "gameUI", {parent:this});
12 | this.gun = this.ui['gun'];
13 | this.initPhysics(this.ui);
14 | flax.inputManager.addListener(this.ui['back'], this.onClick, InputType.click, this);
15 | },
16 | initPhysics:function(ui){
17 | flax.createPhysicsWorld(theGravity);
18 | flax.startPhysicsWorld();
19 |
20 | ui.createPhysics(flax.physicsTypeStatic);
21 | ui.addPhysicsShape("topBar", 1, 0.3, 0.5);
22 | ui.addPhysicsShape("leftBar", 1, 0.3, 0.5);
23 | ui.addPhysicsShape("rightBar", 1, 0.3, 0.5);
24 | ui.addPhysicsShape("leftEdge", 1, 0.3, 0.5);
25 | ui.addPhysicsShape("rightEdge", 1, 0.3, 0.5);
26 | ui.addPhysicsShape("hole", 1, 0.3, 0.5, true);
27 |
28 | // ui.getCollider("leftEdge").debugDraw();
29 | // ui.getCollider("rightEdge").debugDraw();
30 | // ui.getCollider("hole").debugDraw();
31 |
32 | flax.onCollideStart.add(this.onCollid, this);
33 | },
34 | onClick:function(touch, event)
35 | {
36 | var pos = touch.getLocation();
37 | var rot = flax.getAngle(this.gun.getPosition(), pos);
38 | if(rot > 180) rot -= 360;
39 | rot = Math.max(-65, rot);
40 | rot = Math.min(65, rot);
41 | this.gun.rotation = rot;
42 |
43 | var anchor = this.gun.getAnchor("shoot");
44 | pos = cc.p(anchor.x, anchor.y);
45 | pos = this.gun.convertToWorldSpace(pos);
46 |
47 | var ball = flax.assetsManager.createDisplay(res.physics, "b" + flax.randInt(0, 5), {parent:this, zIndex: 99}, true);
48 | ball.setPosition(pos);
49 | ball.createPhysics(flax.physicsTypeDynamic, false, true);
50 | ball.addPhysicsShape("main", 1, 0.3, 0.5);
51 | var v = flax.getPointOnCircle(cc.p(), 1600, rot);
52 | ball.physicsBody.SetLinearVelocity({x: v.x/PTM_RATIO, y: v.y/PTM_RATIO});
53 |
54 | flax.clearDraw();
55 | var pos1 = flax.getPointOnCircle(pos, 600, rot);
56 | flax.physicsRaycast(function(collider,collisionPoint, endPoint, fraction){
57 | if(collider.name != "leftBar" && collider.name != "rightBar") return;
58 | flax.drawLine(pos, collisionPoint, 1, cc.color(0, 255, 0));
59 | flax.drawDot(collisionPoint);
60 | flax.drawLine(collisionPoint, endPoint);
61 | }, pos, pos1, 24);
62 |
63 | // if(this.ui.getCollider("hole").containsPoint(touch.getLocation())){
64 | // cc.log("click");
65 | // }
66 | },
67 | onCollid:function(collider0, collider1)
68 | {
69 | var ball;
70 | if(collider0 && collider0.name == "hole"){
71 | ball = collider1.owner;
72 | }else if(collider1 && collider1.name == "hole"){
73 | ball = collider0.owner;
74 | }
75 | if(ball){
76 | ball.scheduleOnce(ball.destroy, 0.01);
77 | }else{
78 | var mainfold = new Box2D.Collision.b2WorldManifold();
79 | collider0.physicsContact.GetWorldManifold(mainfold);
80 | var contactPoint = cc.pMult(mainfold.m_points[0], PTM_RATIO);
81 | var effect = flax.assetsManager.createDisplay(res.physics, "collideEffect", {parent:this, zIndex: 999, autoDestroyWhenOver:true}, true);
82 | effect.setPosition(contactPoint);
83 | effect.play();
84 | }
85 | }
86 | })
--------------------------------------------------------------------------------
/src/GamePopStars.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-14.
3 | */
4 | var COLS = 8;
5 | var ROWS = 8;
6 | var TILE_SIZE = 64
7 | var MIN_COUNT = 3;
8 |
9 | var GamePopStars = BaseScene.extend({
10 | tileMap:null,
11 | onEnter:function()
12 | {
13 | this._super();
14 |
15 | var bg = flax.assetsManager.createDisplay(res.poppingStars, "bg", {parent:this});
16 | flax.inputManager.addListener(bg, this.onClick, InputType.press, this);
17 |
18 | //create a new TileMap
19 | this.tileMap = new flax.TileMap();
20 | this.tileMap.init(TILE_SIZE, TILE_SIZE);
21 | this.tileMap.setMapSize(ROWS, COLS);
22 | this.tileMap.setPosition(64, 180);
23 | //this.tileMap.showDebugGrid();
24 |
25 | //Initialize the whole map
26 | for(var i = 0; i < ROWS; i++)
27 | {
28 | for(var j = 0; j < COLS; j++)
29 | {
30 | var star = flax.assetsManager.createDisplay(res.poppingStars, "star" + flax.randInt(0, 4), {parent: this}, true);
31 | this.tileMap.snapToTile(star, i, j, true);
32 | }
33 | }
34 | },
35 | onClick:function(touch, event)
36 | {
37 | var pos = touch.getLocation();
38 | var objs = this.tileMap.getObjects1(pos.x, pos.y);
39 | if(objs.length){
40 | var star = objs[0];
41 | var stars = this.tileMap.findConnectedObjects(star, "assetID");
42 | if(stars.length >= MIN_COUNT - 1){
43 | //Destory all the stars with the same assetID(color)
44 | var rowsEffected = [];
45 | stars.push(star);
46 | for(var i = 0; i < stars.length; i++){
47 | star = stars[i];
48 | if(rowsEffected.indexOf(star.tx) == -1) rowsEffected.push(star.tx);
49 | star.destroy();
50 | }
51 | for(var i = 0; i < rowsEffected.length; i++)
52 | {
53 | //The stars above the blank tiles will fall
54 | var row = rowsEffected[i];
55 | var space = 0;
56 | for(var col = 0; col < COLS; col++)
57 | {
58 | objs = this.tileMap.getObjects(row, col);
59 | if(objs.length == 0){
60 | space++;
61 | }else{
62 | star = objs[0];
63 | if(space > 0){
64 | //why not use moveTo action, setPosition will not be called in JSB
65 | // star.runAction(cc.moveTo(0.2, star.x, star.y - TILE_SIZE*space));
66 | star.moveTo(cc.p(star.x, star.y - TILE_SIZE*space), 0.2);
67 | }
68 | }
69 | }
70 | //Create new stars to fall
71 | for(var j = 0; j < space; j++)
72 | {
73 | var targetPos = this.tileMap.getTiledPosition(row, COLS - j - 1);
74 | var newStar = flax.assetsManager.createDisplay(res.poppingStars, "star" + flax.randInt(0, 4), {parent: this}, true);
75 | newStar.tileMap = this.tileMap;
76 | newStar.setPosition(targetPos.x, targetPos.y + 260 + Math.random()*60);
77 | //why not use moveTo action, setPosition will not be called in JSB
78 | // newStar.runAction(cc.moveTo(0.3, targetPos));
79 | newStar.moveTo(targetPos, 0.3);
80 | }
81 | }
82 | }
83 | }
84 | }
85 | })
--------------------------------------------------------------------------------
/src/GameShooters.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-16.
3 | */
4 |
5 | var GameShooters = BaseScene.extend({
6 | onEnter:function()
7 | {
8 | this._super();
9 | flax.assetsManager.createDisplay(res.shooters, "level1",{parent:this});
10 | }
11 | })
12 |
13 | var thePropNames = ["HealProp", "MultiProp", "SpeedProp", "ArmorProp"];
14 |
15 | var BattleStage = flax.MovieClip.extend({
16 | enemies:null,
17 | props:null,
18 | onEnter:function()
19 | {
20 | this._super();
21 | //Init the global bullet container(SpriteBatchNode)
22 | flax.BulletCanvas.create(res.shooters, this);
23 | this.initElements();
24 | //Set the enemies as the player's target
25 | //TODO, there is another method with TileMap to check the bullet collision in Flax
26 | this['player'].targets = this.enemies;
27 | this['player'].props = this.props;
28 | //Scrolling background
29 | // var bg = new flax.ScrollingBG(this.bg);
30 | // bg.startYScroll(-50);
31 | },
32 | initElements:function()
33 | {
34 | this.enemies = [];
35 | this.props = [];
36 | for(var i = 0; i < this.getChildrenCount(); i++){
37 | var child = this.children[i];
38 | if(child instanceof Enemy){
39 | this.enemies.push(child);
40 | }else if(thePropNames.indexOf(child.assetID) > -1){
41 | this.props.push(child);
42 | }
43 | }
44 | }
45 | })
46 | /**
47 | * More available param in flax.GunParam of Gun.js
48 | * */
49 | var PlayerGunParam = {
50 | bulletAssets:res.shooters,//the assets file of the bullet
51 | bulletID:"Bullet0",//the id of the bullet asset
52 | targetMap:null,//the TileMap name of the target to shoot
53 | damage:10,//the damage of the bullet, if it's Array with two elements, set a random value between them
54 | interval:0.5,//the interval time between two launch
55 | fireSound:null,//music.gun0,//the sound when fire
56 | fireEffectID:"FireEffect",//the id of fire effect, it must be packed with the bullet asset id together
57 | hitEffectID:"HitEffect"//the id of hit effect, it must be packed with the bullet assets id together
58 | }
59 |
60 | var EnemyGunParam = {
61 | bulletAssets:res.shooters,//the assets file of the bullet
62 | bulletID:"EnemyBullet",//the id of the bullet asset
63 | targetMap:null,//the TileMap name of the target to shoot
64 | damage:1,//the damage of the bullet, if it's Array with two elements, set a random value between them
65 | interval:0.5,//the interval time between two launch
66 | fireSound:null,//music.gun1,//the sound when fire
67 | fireEffectID:"FireEffect",//the id of fire effect, it must be packed with the bullet asset id together
68 | hitEffectID:"HitEffect"//the id of hit effect, it must be packed with the bullet assets id together
69 | }
70 |
71 | var Player = flax.Gunner.extend({
72 | props:null,
73 | onEnter:function()
74 | {
75 | this._super();
76 | this.health = this.maxHealth = 1000;
77 | this.setGunParam(PlayerGunParam, ["weapon0", "weapon1"]);
78 | this.autoShoot();
79 | this.gotoAndPlay(0);
80 | flax.inputManager.addListener(this, this.onDrag, InputType.move, this)
81 | },
82 | onDrag:function(touch, event)
83 | {
84 | this.setPosition(touch.getLocation());
85 | //check the props
86 | for(var i = 0; i < this.props.length; i++){
87 | var prop = this.props[i];
88 | if(prop.mainCollider.checkCollision(this.mainCollider)){
89 | prop.destroy();
90 | switch(prop.assetID){
91 | case "MultiProp":
92 | this.upgradeGun({count:2}, 10)
93 | break;
94 | case "SpeedProp":
95 | this.upgradeGun({interval:-0.2}, 10);
96 | break;
97 | case "ArmorProp":
98 | this.hurtable = false;
99 | var armor = flax.assetsManager.createDisplay(res.shooters, "HealCircle", {parent: this}, true);
100 | armor.setPosition(cc.pAdd(this.getAnchorPointInPoints(),cc.p(0, 35)))
101 | armor.gotoAndPlay(0);
102 | this.scheduleOnce(function(){
103 | armor.destroy();
104 | this.hurtable = true;
105 | }, 10);
106 | break
107 | case "HealProp":
108 | var healAnim = flax.assetsManager.createDisplay(res.shooters, "HealEffect",{parent: this, autoDestroyWhenOver: true}, true);
109 | healAnim.setPosition(this.getAnchorPointInPoints());
110 | healAnim.gotoAndPlay(0);
111 | this.health = Math.min(this.maxHealth, this.health + 100);
112 | break;
113 | }
114 | }
115 | }
116 | },
117 | onDie:function()
118 | {
119 | this._super();
120 | }
121 | })
122 |
123 | var Enemy = flax.MCGunner.extend({
124 | onEnter:function()
125 | {
126 | this._super();
127 | this.health = this.maxHealth = 100;
128 | this.setGunParam(EnemyGunParam, ["weapon0"]);
129 | this.autoShoot();
130 | //The enemy always aim to the player
131 | this.aimToTarget(this.parent['player']);
132 | //Auto play children's animation when this is playing
133 | this.autoPlayChildren = true;
134 | this.sameFpsForChildren = false;
135 | this.gotoAndPlay("180");
136 | },
137 | onAimingTarget:function(angle)
138 | {
139 | angle = Math.round(angle/45)*45;
140 | if(angle == 360) angle = 0;
141 | this.gotoAndPlay("" + angle);
142 | },
143 | onDie:function()
144 | {
145 | var targets = this.parent['player'].targets;
146 | //Play die animation
147 | var dieAnim = flax.assetsManager.createDisplay(res.shooters, "EnemyDeath", {parent: this.parent, x: this.x, y: this.y, zIndex: this.zIndex}, true);
148 | dieAnim.autoDestroyWhenOver = true;
149 | dieAnim.onAnimationOver.add(function(anim){
150 | //New born enemy
151 | var newEnemy = flax.assetsManager.createDisplay(res.shooters, "Enemy", {parent: anim.parent, x: anim.x, y: anim.y, zIndex: anim.zIndex}, true);
152 | targets.push(newEnemy);
153 | }, this);
154 | dieAnim.gotoAndPlay(0);
155 |
156 | var i = targets.indexOf(this);
157 | if(i > -1) targets.splice(i, 1);
158 |
159 | this._super();
160 | }
161 | })
162 | //Avoid the following class to be obscured in advanced compiled mode
163 | window['BattleStage'] = BattleStage;
164 | window['Player'] = Player;
165 | window['Enemy'] = Enemy;
--------------------------------------------------------------------------------
/src/GameTimberQiang.js:
--------------------------------------------------------------------------------
1 | TREE_X = 323;
2 | TREE_Y = 138;
3 | SEG_H = 124;
4 | MAX_TIME = 6;
5 | START_TIME = 3;
6 | CLICK_TIME = 0.25;
7 |
8 | var score = 0;
9 | var gameOver = false;
10 |
11 | var MainGame = flax.MovieClip.extend({
12 | treeBatch:null,
13 | _currentY:0,
14 | _deathTree:false,
15 | _time:0,
16 | _started:false,
17 | onEnter:function(){
18 | this._super();
19 | this['t0'].play();
20 | this['t1'].play();
21 | this['player'].autoStopWhenOver = true;
22 | this['player'].zIndex = 2;
23 | this['player'].scale = 1.2;
24 | this['player'].side = 1;
25 | score = 0;
26 | gameOver = false;
27 | this['scoreTxt'].gap = -2;
28 | this['scoreTxt'].setString(0);
29 | flax.inputManager.addListener(this, this.onTouch,null, this)
30 | this.treeBatch = cc.SpriteBatchNode.create(cc.path.changeBasename(res.timberQiang, ".png"), 8);
31 | this.addChild(this.treeBatch, 2);
32 | this.initTree();
33 |
34 | this._time = START_TIME;
35 | this['energy']['bar'].percentage = 100*this._time/MAX_TIME;
36 | this.scheduleUpdate();
37 | },
38 | update:function(delta){
39 | if(!this._started || gameOver) return;
40 | this._time -= 1.8*delta*this['energy']['bar'].percentage/100;
41 | this._time -= 0.6*delta*Math.min(Math.max(0.5, 0.5*score/100),2);
42 | this['energy']['bar'].percentage = 100*this._time/MAX_TIME;
43 | if(this._time <= 0){
44 | this.unscheduleUpdate();
45 | this.onFailed();
46 | }
47 | },
48 | onTouch:function(touch, event){
49 | if(gameOver) return;
50 | this._started = true;
51 | if(this['t0']){
52 | this['t0'].destroy();
53 | this['t1'].destroy();
54 | this['t0'] = null;
55 | this['t1'] = null;
56 | }
57 | var pos = touch.getLocation();
58 | if(pos.x > cc.visibleRect.width/2){
59 | this['player'].scaleX = -1;
60 | this['player'].side = 2;
61 | }else{
62 | this['player'].scaleX = 1;
63 | this['player'].side = 1;
64 | }
65 | flax.playSound(music.chop);
66 |
67 | this['player'].gotoAndPlay(0);
68 |
69 | var tSide = this.treeBatch.getChildren()[0].side;
70 | if(tSide != 0 && tSide == this['player'].side){
71 | this.onFailed();
72 | }else{
73 | tSide = this.treeBatch.getChildren()[1].side;
74 | if( tSide == 0 || tSide != this['player'].side){
75 | score += 1;
76 | this._time += CLICK_TIME;
77 | this['scoreTxt'].setString(score);
78 | this.showTreeAnim();
79 | this['energy'].runAction(cc.Sequence.create(cc.ScaleTo.create(0.1, 1.1),cc.ScaleTo.create(0.1, 1.0)));
80 | }else{
81 | this.onFailed();
82 | }
83 | this.treeBatch.removeChildAtIndex(0, true);
84 | this.treeBatch.runAction(cc.MoveTo.create(0.1, cc.p(this.treeBatch.x, this.treeBatch.y - SEG_H)))
85 | this.createTreeSegment();
86 | }
87 | },
88 | initTree:function(){
89 | var t = flax.assetsManager.createDisplay(res.timberQiang, "tree0",{parent: this.treeBatch}, true);
90 | t.x = TREE_X;
91 | t.side = 0;
92 | this._currentY = t.y = TREE_Y + SEG_H/2;
93 | for(var i = 1; i < 6; i++){
94 | var tn = null;
95 | if(i < 3) tn = "tree0";
96 | this.createTreeSegment(tn);
97 | }
98 | },
99 | onFailed:function(){
100 | var death = flax.assetsManager.createDisplay(res.timberQiang,"death", {parent: this, zIndex:200}, true);
101 | death.x = (this['player'].side == 1) ? 150 : 500;
102 | death.y = 240;
103 | death.runAction(cc.MoveTo.create(0.3, cc.p(death.x, 150)));
104 | this['player'].destroy();
105 | this.scheduleOnce(function(){
106 | flax.assetsManager.createDisplay(res.timberQiang,"ResultPanel",{parent: this, zIndex:1000});
107 | },0.5);
108 | flax.playSound(music.fail);
109 | flax.inputManager.removeListener(null, this.onTouch);
110 | },
111 | showTreeAnim:function(){
112 | var anim = flax.assetsManager.createDisplay(res.timberQiang,"treeAnim",{parent: this, zIndex:2,autoDestroyWhenOver:true}, false);
113 | anim.fps = 60;
114 | anim.setPosition(TREE_X,TREE_Y + SEG_H - 65);
115 | anim.replaceChild("tree",this.treeBatch.getChildren()[0].assetID);
116 | anim.play();
117 | if(this['player'].side == 2) anim.scaleX = -1;
118 | },
119 | createTreeSegment:function(tn){
120 | var i = 0;
121 | if(tn == null) {
122 | if(!this._deathTree) i = flax.randInt(1, 3);
123 | tn = "tree"+i;
124 | this._deathTree = i > 0;
125 | }
126 | this._currentY += SEG_H;
127 | var t = flax.assetsManager.createDisplay(res.timberQiang, tn,{parent: this.treeBatch}, true);
128 | t.x = TREE_X;
129 | t.y = this._currentY;
130 | t.side = i;
131 | }
132 | });
133 |
134 | var GameScene = BaseScene.extend({
135 | onEnter:function(){
136 | this._super();
137 |
138 | flax.playMusic(music.bg);
139 |
140 | var ui = flax.assetsManager.createDisplay(res.timberQiang, "MainGame");
141 | this.addChild(ui);
142 | }
143 | });
144 |
145 | var MenuScene = BaseScene.extend({
146 | onEnter:function(){
147 | this._super();
148 | var ui = flax.assetsManager.createDisplay(res.timberQiang, "MainMenu");
149 | this.addChild(ui);
150 | flax.inputManager.addListener(ui['startBtn'], function(){
151 | flax.replaceScene("timberQiangGame");
152 | });
153 | ui['player'].play();
154 | }
155 | })
156 |
157 | var ResultPanel = flax.MovieClip.extend({
158 | onEnter:function(){
159 | this._super();
160 | gameOver = true;
161 | flax.inputManager.addListener(this['startBtn'], function(){
162 | flax.replaceScene("timberQiangGame");
163 | },null, this);
164 |
165 | this['scoreTxt'].setString(parseInt(score));
166 | var record = false;
167 | if(flax.userData['score'] < score){
168 | flax.userData['score'] = score;
169 | flax.saveUserData();
170 | record = true;
171 | }
172 | this['bestTxt'].setString(parseInt(flax.userData['score']));
173 | }
174 | });
175 |
176 | //Avoid the following class to be obscured in advanced compiled mode
177 | window['MainGame'] = MainGame;
178 | window['ResultPanel'] = ResultPanel;
--------------------------------------------------------------------------------
/src/ScrollingBGTest.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-17.
3 | */
4 |
5 | var ScrollingBGTest = BaseScene.extend({
6 | onEnter:function()
7 | {
8 | this._super();
9 | var ui = flax.assetsManager.createDisplay(res.scrollingBG, "ui", {parent:this});
10 |
11 | var sbg = new flax.ScrollingBG(ui['bg']);
12 | //Following bgs is optional
13 | //下面添加的更多背景是可选的
14 | sbg.addSource(res.scrollingBG, "bg0");
15 | sbg.addSource(res.scrollingBG, "bg1");
16 | //如果scroll的loop设为false,滚动结束会触发这个事件
17 | //if the loop is flase when scroll, scroll over will trigger this event
18 | sbg.onScrolledOver.add(this._onScrolledOver, this);
19 |
20 | ui['resetBtn']['label'].text = flax.getLanguageStr("reset");
21 | ui['startxBtn']['label'].text = flax.getLanguageStr("startx");
22 | ui['startyBtn']['label'].text = flax.getLanguageStr("starty");
23 | ui['pauseBtn']['label'].text = flax.getLanguageStr("pause");
24 | ui['resumeBtn']['label'].text = flax.getLanguageStr("resume");
25 |
26 | flax.inputManager.addListener(ui['resetBtn'], function(){
27 | sbg.reset();
28 | },null, this);
29 |
30 | flax.inputManager.addListener(ui['startxBtn'], function(){
31 | sbg.startXScroll(this._getSpeed(), false);
32 | },null, this);
33 | flax.inputManager.addListener(ui['startyBtn'], function(){
34 | sbg.startYScroll(this._getSpeed());
35 | },null, this);
36 | flax.inputManager.addListener(ui['pauseBtn'], function(){
37 | sbg.pauseScroll();
38 | },null, this);
39 | flax.inputManager.addListener(ui['resumeBtn'], function(){
40 | sbg.resumeScroll();
41 | },null, this);
42 | },
43 | _getSpeed:function()
44 | {
45 | var s = 200 + Math.random()*800;
46 | return (Math.random() > 0.5) ? -s : s;
47 | },
48 | _onScrolledOver:function()
49 | {
50 | cc.log("Scrolled over!");
51 | }
52 | })
--------------------------------------------------------------------------------
/src/SkeletonAndControl.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-10.
3 | */
4 | var SkeletonAndControl = BaseScene.extend({
5 | skeleton:null,
6 | ctrPanel:null,
7 | onEnter:function(){
8 | this._super();
9 | //产生动画
10 | //Create a skeleton animation
11 | this.skeleton = flax.assetsManager.createDisplay(res.skeleton, "monkey", {parent:this, x: cc.visibleRect.center.x - 100, y: cc.visibleRect.center.y});
12 | //Auto play children's animation when monkey playing, so the monkey can blink his eyes when gotoAndPlay("idle")
13 | //当播放这个骨骼动画时,自动播放子元素动画, 所以猴子在gotoAndPlay("idle")时可以眨眼
14 | this.skeleton.autoPlayChildren = true;
15 | //侦听每一帧改变事件:渲染一帧调用一次,频率为动画本身的fps
16 | //Listening the frame change signal, one callback one frame, the rate is according by the fps of the animation
17 | this.skeleton.onFrameChanged.add(this._onFrameChanged, this);
18 | //侦听帧Label事件
19 | //Listening the frame label change signal
20 | this.skeleton.onFrameLabel.add(this._onFrameLabel, this);
21 | //侦听动画完毕事件:如果是play(),最后一帧发出;如果是gotoAndPlay("anim"), anim动画的最后一帧发出
22 | //Listening the animation over signal, if tricked by play(), sent on the last frame;
23 | //or if gotoAndPlay("anim"), sent on the last frame of the animation "anim"
24 | this.skeleton.onAnimationOver.add(this._onAnimationOver, this);
25 | //侦听序列动画完毕事件: 当playSequence或playSequenceLoop时,在一个sequence结束时发出
26 | //Listening the animation sequence signal, sent when playSequence or playSequenceLoop is over
27 | this.skeleton.onSequenceOver.add(this._onSequenceOver, this);
28 | //控制面板
29 | //Control panel
30 | this.ctrPanel = flax.assetsManager.createDisplay(res.skeleton, "ControlPanel", {parent:this});
31 | //侦听按钮事件
32 | //Listening the buttons click
33 | var children = this.ctrPanel.getChildren();
34 | for(var i = 0; i < children.length; i++){
35 | var child = children[i];
36 | if(flax.isButton(child)){
37 | flax.inputManager.addListener(child, this._controlAnim, InputType.click, this);
38 | }
39 | }
40 | this._onFrameChanged(0);
41 | },
42 | _controlAnim:function(touch, event)
43 | {
44 | var btn = event.currentTarget;
45 | cc.log("Command: " + btn['label'].text);
46 | //执行动画控制命令
47 | //Execute the animation control command
48 | eval("this.skeleton."+btn['label'].text);
49 | if(this.skeleton['head']){
50 | //Replace the head with anotherHead in this.skeleton's assetsFile
51 | this.skeleton.replaceChild("head", "anotherHead");
52 | //Replace the head with anotherHead in another assetsFile
53 | // this.skeleton.replaceChild("head", "anotherHead", res.animation);
54 | }
55 | },
56 | _onFrameChanged:function(frame)
57 | {
58 | //注: frame即this.skeleton.currentFrame
59 | //Note: frame is just the same as this.skeleton.currentFrame
60 | this.ctrPanel['infoTxt'].text = "FPS: " + this.skeleton.fps +", currentFrame: " + frame + ", playing: " + this.skeleton.playing + "\ncurrentLabel: " + this.skeleton.currentLabel + ", currentAnim: " + this.skeleton.currentAnim;
61 | },
62 | _onFrameLabel:function(label)
63 | {
64 | // this._showMsg("Frame label: " + label);
65 | cc.log("Frame label: " + label);
66 | },
67 | _onAnimationOver:function(sprite)
68 | {
69 | this._showMsg("Animation over!");
70 | },
71 | _onSequenceOver:function(sprite)
72 | {
73 | // this._showMsg("Sequence over!");
74 | cc.log("Sequence over!");
75 | },
76 | _showMsg:function(msg)
77 | {
78 | //注意第四个参数为true,对象销毁时将放入对象池,产生的时候优先从对象池拿取
79 | //Note the forth param is true, which means the animation will be put in the object pool when destroy
80 | //And fetch a new one from the pool
81 | var infoAnim = flax.assetsManager.createDisplay(res.skeleton, "InfoAnim", {parent: this, x : 140 + Math.random()*400, y : 300 + 500*Math.random()}, true);
82 | //文本信息
83 | //Text message
84 | infoAnim['info']['txt'].text = msg;
85 | //autoDestroyWhenOver: 表示动画完毕时,自动销毁,适合特效类动画 (Means auto destroy when animation is over, is good choice for effect animation)
86 | //autoStopWhenOver: 动画完毕时停在当前帧 (Stop at the current frame when animation is over)
87 | //autoHideWhenOver: 动画完毕时自动隐藏 (Hide itself when animation is over)
88 | infoAnim.autoDestroyWhenOver = true;
89 | //开始播放 (Start play animation)
90 | infoAnim.gotoAndPlay(0);
91 | }
92 | })
93 | //Avoid the properties or methods to be obscured in advanced compiled mode
94 | /** @expose */
95 | SkeletonAndControl.prototype.skeleton;
96 | /** @expose */
97 | flax.FlaxSprite.prototype.play;
98 | /** @expose */
99 | flax.FlaxSprite.prototype.stop;
100 | /** @expose */
101 | flax.FlaxSprite.prototype.gotoAndPlay;
102 | /** @expose */
103 | flax.FlaxSprite.prototype.gotoAndStop;
104 | /** @expose */
105 | flax.FlaxSprite.prototype.playSequence;
106 | /** @expose */
107 | flax.FlaxSprite.prototype.playSequenceLoop;
--------------------------------------------------------------------------------
/src/TiledImageTest.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-17.
3 | */
4 |
5 | var TiledImageTest = BaseScene.extend({
6 | onEnter:function()
7 | {
8 | this._super();
9 | var tImg = new flax.TiledImage(res.tiledImage, "tile1");
10 | this.addChild(tImg);
11 |
12 | flax.inputManager.addListener(tImg, function(){
13 | tImg.setTileSource(res.tiledImage, "tile0");
14 | for(var i = 0; i < tImg.getChildrenCount(); i++){
15 | if(Math.random() > 0.7){
16 | tImg.children[i].gotoAndStop(flax.randInt(0, 5));
17 | }else{
18 | tImg.children[i].gotoAndStop(0);
19 | }
20 | }
21 | })
22 | }
23 | })
--------------------------------------------------------------------------------
/src/UIBMFont.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-14.
3 | */
4 |
5 | /**
6 | * 为了让某些使用特殊字体的TTF文本能正确显示,请提前注册它所使用的字体
7 | * To make some TTF TextField used special font to display correctly, pleas pre-register its font
8 | * */
9 | if(!cc.sys.isNative) flax.registerFont("AntsyPants", "res/font/ANTSYPAN.TTF");
10 |
11 | var UIBmFont = BaseScene.extend({
12 | onEnter:function()
13 | {
14 | this._super();
15 |
16 | //注意uiBmFont.fla里的背景元件share.uiPanel.PanelBack,这个元件是从uiPanel.fla里共享的,assetID为PanelBack的元件
17 | //Note the background symbol of share.uiPanel.PanelBack in uiBmFont.fla, it is shared from the uiPanel.fla with assetID PanelBack
18 | var panel = flax.assetsManager.createDisplay(res.uiBMFont, "BMPanel", {parent:this});
19 |
20 | //注意uiBmFont.fla里,有一个ttf文本名叫:titleTxt__bmp,在程序中通过titleTxt来访问它,通过bmp这个ID切换多语言
21 | // 见locale/en.json or locale/zh.json,记住,project.json中languageJson必须为true才能开启多语言模式
22 | //Note the ttf TextField named titleTxt__bmp in the uiBmFont.fla, we visit it with name titleTxt, and update the multi-language
23 | //by the ID of bmp, see the locale/en.json or locale/zh.json
24 | //Remember: the property of languageJson must be true in project.json
25 |
26 | //panel.titleTxt.text = flax.getLanguageStr("bmp");
27 |
28 | //设置文本值
29 | //Set the text value
30 | panel['scoreTxt0'].text = 6666;
31 |
32 | panel['scoreTxt1'].text = 6666;
33 | //调整字符间距,spaceGap用于调整空格字符长度
34 | //Adjust the gap between the chars, spaceGap is used for adjusting the width of the space char
35 | panel['scoreTxt1'].gap = 5;
36 |
37 | //如果字符过多,文本将会自动缩放到文本框的矩形范围内
38 | //If the chars are too much for the text, it will auto scale down to fit in the rect
39 | panel['scoreTxt2'].text = 9999999;
40 |
41 | //5秒内从0跳到66666, 5秒的时间不精准
42 | //Tween the value from 0 to 66666 in 5 seconds, the time is not very accurate
43 | panel['scoreTxt3'].tweenInt(0, 66666, 5);
44 | }
45 | })
--------------------------------------------------------------------------------
/src/UIButton.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-13.
3 | */
4 | var UIButton = BaseScene.extend({
5 | onEnter:function()
6 | {
7 | this._super();
8 |
9 | var panel = flax.assetsManager.createDisplay(res.uiButton, "ButtonPanel", {parent: this});
10 |
11 | panel['simpleBtn2'].setMouseEnabled(false);
12 | panel['labelBtn2'].setMouseEnabled(false);
13 |
14 | //animBtn是一个很复杂的按钮,通过一个collider.Circle的元件,可限定其点击范围, 更多的collider我们将在后面示例中添加,包括物理编辑
15 | //animBtn is a complicated button, Flax defined its clickable area by a symbol of collider.Circle,
16 | // we will give more detail about collider in future include physics edit
17 | panel['animBtn'].playChildrenOnState = true;
18 | panel['animBtn'].clickSound = music.chop;
19 | flax.inputManager.addListener(panel['animBtn'], function(){
20 | panel['groupBtn2'].selected = true;
21 | })
22 |
23 | //设置按钮Label,并支持多语言,多语言配置json在res/locale/中
24 | //Set the Label for these buttons, and support multi-language, the language json is placed at res/locale/
25 | panel['groupBtn0']['label'].text = flax.getLanguageStr("Tab") + "0";
26 | panel['groupBtn1']['label'].text = flax.getLanguageStr("Tab") + "1";
27 | panel['groupBtn2']['label'].text = flax.getLanguageStr("Tab") + "2";
28 |
29 | //按钮组
30 | //Button Group
31 | var group = new flax.ButtonGroup();
32 | group.addButton(panel['groupBtn0'], panel['groupBtn1'], panel['groupBtn2']);
33 | group.onSelected.add(this._onButtonGroupChange);
34 |
35 | panel['groupBtn0'].selected = true;
36 | },
37 | _onButtonGroupChange:function(selected)
38 | {
39 | cc.log("Tab selected: " + selected.name);
40 | }
41 | })
--------------------------------------------------------------------------------
/src/UIInput.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-3-6.
3 | */
4 |
5 | var UIInput = BaseScene.extend({
6 | onEnter:function(){
7 | this._super();
8 | var ui = flax.assetsManager.createDisplay(res.uiInput, "InputPanel",{parent:this});
9 | //password input
10 | ui['pswTxt'].setInputFlag(cc.EDITBOX_INPUT_FLAG_PASSWORD);
11 | ui['pswTxt'].setMaxLength(12);
12 | //set the placeholder font color
13 | ui['telTxt'].setPlaceholderFontColor(cc.color(51, 51, 51));
14 | //The input text is just EditBox, so you can do anything the EditBox can do
15 | ui['telTxt'].setDelegate(this);
16 | },
17 | editBoxEditingDidBegin: function (editBox) {
18 | cc.log(editBox.name + " DidBegin!");
19 | },
20 | editBoxEditingDidEnd: function (editBox) {
21 | cc.log(editBox.name + " DidEnd: " + editBox.getString());
22 | },
23 | editBoxTextChanged: function (editBox, text) {
24 | cc.log(editBox.name + " , TextChanged, text: " + text);
25 | },
26 | editBoxReturn: function (editBox) {
27 | cc.log(editBox.name + " was returned!");
28 | }
29 | })
--------------------------------------------------------------------------------
/src/UIPanel.js:
--------------------------------------------------------------------------------
1 |
2 | var userInfo = {coins: 900, energy: 100};
3 | var itemsCount = [1, 5, 3, 10];
4 | var itemsPrice = [100, 200, 300, 500];
5 |
6 | var UIPanelScene = BaseScene.extend({
7 | onEnter:function(){
8 | this._super();
9 | //产生一个面板,注意面板背景元件jpg.PanelBack,jpg表示这个素材会被输出为单独的jpg而非打包到贴图里
10 | //Create a UI panel, note the background symbol of jpg.PanelBack, jpg means the asset will be exported as a single jpg file
11 | //instead of packing into the texture
12 | var panel = flax.assetsManager.createDisplay(res.uiPanel, "storePanel", {parent: this});
13 | //将子动画播放
14 | //Play a child animation
15 | panel['playBtn'].play();
16 | //显示用户数据
17 | //Update the user info
18 | panel['coinsTxt'].text = userInfo.coins;
19 | panel['energyTxt'].text = userInfo.energy;
20 | //显示商店物品数据
21 | //Update the shop items info
22 | for(var i = 0; i < 4; i++)
23 | {
24 | var item = panel["p" + i];
25 | item['icon'].gotoAndStop(i);
26 | item['countTxt'].text = itemsCount[i];
27 | item['priceTxt'].text = itemsPrice[i];
28 | item.__index = i;
29 | //侦听商店物品点击事件
30 | //Listening the click event of the shop item
31 | flax.inputManager.addListener(item, this._onItemClick, InputType.click, this);
32 | }
33 | //侦听playBtn的点击事件
34 | //Listening the click event of the playBtn
35 | flax.inputManager.addListener(panel['playBtn'], this._onPlayClick, InputType.click, this);
36 | },
37 | _onItemClick:function(touch, event)
38 | {
39 | //currentTarget就是我们点选的物品
40 | //currentTarget is just the shop item we clicked
41 | var item = event.currentTarget;
42 | cc.log("NO." + item.__index + " item was clicked, its price is: " + item['priceTxt'].text);
43 | },
44 | _onPlayClick:function(touch, event)
45 | {
46 | cc.log("playBtn was clicked!");
47 | }
48 | });
--------------------------------------------------------------------------------
/src/UIProgress.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-2-13.
3 | */
4 | var UIProgress = BaseScene.extend({
5 | onEnter:function()
6 | {
7 | this._super();
8 |
9 | var panel = flax.assetsManager.createDisplay(res.uiProgress, "ProgressPanel", {parent: this});
10 | //水平进度条
11 | //Horizontal progress bar
12 | panel['p0']['bar'].percentage = 20 + Math.random()*70;
13 |
14 | panel['p1']['bar'].tween(0, 20 + Math.random()*70, 10);
15 |
16 | panel['p2']['bar'].reversed = true;
17 | panel['p2']['bar'].tween(0, 20 + Math.random()*70, 10);
18 |
19 | panel['p3']['bar'].type = flax.ProgressBarType.VERTICAL;
20 | panel['p3']['bar'].percentage = 20 + Math.random()*70;
21 |
22 | //垂直进度条
23 | //Vertical progress bar
24 | panel['p4']['bar'].type = flax.ProgressBarType.VERTICAL;
25 | panel['p4']['bar'].tween(0, 20 + Math.random()*70, 10);
26 |
27 | panel['p5']['bar'].type = flax.ProgressBarType.VERTICAL;
28 | panel['p5']['bar'].reversed = true;
29 | panel['p5']['bar'].tween(0, 20 + Math.random()*70, 10);
30 |
31 | panel['p6']['bar'].type = flax.ProgressBarType.RADIAL
32 | panel['p6']['bar'].percentage = 20 + Math.random()*70;
33 |
34 | //圆形进度条
35 | //Radial progress bar
36 | panel['p7']['bar'].type = flax.ProgressBarType.RADIAL
37 | panel['p7']['bar'].tween(0, 20 + Math.random()*70, 10);
38 |
39 | panel['p8']['bar'].type = flax.ProgressBarType.RADIAL
40 | panel['p8']['bar'].reversed = true;
41 | panel['p8']['bar'].tween(0, 20 + Math.random()*70, 10);
42 |
43 | //带动画的进度条,注意class参数,表示产生的显示对象是flax.ProgressBar类,而不是默认的flax.Animator
44 | //ProgressBar with animation, note the param of class, which means the display object is flax.ProgressBar instead of the default flax.Animator
45 | var anim = flax.assetsManager.createDisplay(res.animation, "monkey_run", {parent: this, x: 160,y: 280, "class":"flax.ProgressBar"});
46 | anim.percentage = 60;
47 | anim.play();
48 | }
49 | })
--------------------------------------------------------------------------------
/src/flax/core/Animator.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 14-2-1.
3 | */
4 |
5 | flax.Animator = flax.FlaxSprite.extend({
6 | frameNames:null,
7 | clsName:"flax.Animator",
8 | onNewSource:function()
9 | {
10 | var startFrame = this.define['start'];
11 | var endFrame = this.define['end'];
12 |
13 | this.frameNames = flax.assetsManager.getFrameNames(this.assetsFile, startFrame, endFrame);
14 | this.totalFrames = this.frameNames.length;
15 | if(this.totalFrames == 0)
16 | {
17 | cc.log("There is no frame for display: "+this.assetID);
18 | return;
19 | }
20 | },
21 | doRenderFrame:function(frame)
22 | {
23 | this.setSpriteFrame(this.frameNames[frame]);
24 | },
25 | getDefine:function()
26 | {
27 | var define = flax.assetsManager.getDisplayDefine(this.assetsFile, this.assetID);
28 | if(define == null) throw "There is no Animator named: " + this.assetID + " in assets: " + this.assetsFile + ", or make sure this class extends from the proper class!";
29 | return define;
30 | }
31 | });
32 |
33 | flax.Animator.create = function(assetsFile, assetID)
34 | {
35 | var mc = new flax.Animator(assetsFile, assetID);
36 | mc.clsName = "flax.Animator";
37 | return mc;
38 | };
39 |
40 | //Avoid to advanced compile mode
41 | window['flax']['Animator'] = flax.Animator;
--------------------------------------------------------------------------------
/src/flax/core/DebugDraw.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 14-8-19.
3 | */
4 |
5 | flax.__drawNode = null;
6 |
7 | flax.createDrawNode = function(parent, zIndex){
8 |
9 | if(flax.__drawNode && flax.__drawNode.parent && !parent) return;
10 |
11 | if(flax.__drawNode == null) {
12 | flax.__drawNode = cc.DrawNode.create();
13 | }
14 | if(flax.currentScene) {
15 | if(!parent) parent = flax.currentScene;
16 | if(flax.__drawNode.parent && flax.__drawNode.parent != parent){
17 | flax.__drawNode.removeFromParent();
18 | flax.__drawNode.clear();
19 | }
20 | if(flax.__drawNode.parent == null) parent.addChild(flax.__drawNode);
21 | flax.__drawNode.zIndex = zIndex || 99999;
22 | }
23 | };
24 |
25 | flax.clearDraw = function(destroy)
26 | {
27 | if(flax.__drawNode == null) return;
28 | flax.__drawNode.clear();
29 | if(destroy === true) {
30 | flax.__drawNode.removeFromParent();
31 | flax.__drawNode = null;
32 | }
33 | };
34 |
35 | flax.drawLine = function(from, to, lineWidth, lineColor)
36 | {
37 | flax.createDrawNode();
38 | if(lineWidth == null) lineWidth = 1;
39 | if(lineColor == null) lineColor = cc.color(255, 0, 0, 255);
40 | flax.__drawNode.drawSegment(from, to, lineWidth, lineColor);
41 | };
42 | flax.drawRay = function(from, rotation, length, lineWidth, lineColor)
43 | {
44 | flax.drawLine(from, flax.getPointOnCircle(from, length, rotation), lineWidth, lineColor);
45 | };
46 | flax.drawRect = function(rect, lineWidth, lineColor, fillColor)
47 | {
48 | flax.createDrawNode();
49 | if(lineWidth == null) lineWidth = 1;
50 | if(lineColor == null) lineColor = cc.color(255, 0, 0, 255);
51 | var dp = cc.pAdd(cc.p(rect.x, rect.y), cc.p(rect.width, rect.height));
52 | flax.__drawNode.drawRect(cc.p(rect.x, rect.y), dp, fillColor, lineWidth, lineColor);
53 | };
54 | flax.drawStageRect = function()
55 | {
56 | var w = h = 2;
57 | flax.drawRect(cc.rect(flax.stageRect.x + w, flax.stageRect.y + h, flax.stageRect.width - 2*w, flax.stageRect.height - 2*h));
58 | }
59 | flax.drawCircle = function(center, radius, lineWidth, lineColor)
60 | {
61 | flax.createDrawNode();
62 | if(lineWidth == null) lineWidth = 1;
63 | if(lineColor == null) lineColor = cc.color(255, 0, 0, 255);
64 | flax.__drawNode.drawCircle(center, radius, 360, 360, false, lineWidth, lineColor);
65 | };
66 | flax.drawDot = function(center, radius, color)
67 | {
68 | flax.createDrawNode();
69 | if(radius == null) radius = 3;
70 | if(color == null) color = cc.color(255, 0, 0, 255);
71 | flax.__drawNode.drawDot(center, radius,color);
72 | };
--------------------------------------------------------------------------------
/src/flax/core/FlaxLoader.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 14-12-29.
3 | */
4 |
5 | /** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */
6 | /**rawinflate*/
7 | (function() {'use strict';var l=this;function p(b,e){var a=b.split("."),c=l;!(a[0]in c)&&c.execScript&&c.execScript("var "+a[0]);for(var d;a.length&&(d=a.shift());)!a.length&&void 0!==e?c[d]=e:c=c[d]?c[d]:c[d]={}};var q="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function t(b){var e=b.length,a=0,c=Number.POSITIVE_INFINITY,d,f,g,h,k,m,r,n,s,J;for(n=0;na&&(a=b[n]),b[n]>=1;J=g<<16|n;for(s=m;s>>=1;switch(b){case 0:var e=this.input,a=this.d,c=this.b,d=this.a,f=e.length,g=void 0,h=void 0,k=c.length,m=void 0;this.c=this.f=0;if(a+1>=f)throw Error("invalid uncompressed block header: LEN");g=e[a++]|e[a++]<<8;if(a+1>=f)throw Error("invalid uncompressed block header: NLEN");h=e[a++]|e[a++]<<8;if(g===~h)throw Error("invalid uncompressed block header: length verify");if(a+g>e.length)throw Error("input buffer is broken");switch(this.i){case w:for(;d+
10 | g>c.length;){m=k-d;g-=m;if(q)c.set(e.subarray(a,a+m),d),d+=m,a+=m;else for(;m--;)c[d++]=e[a++];this.a=d;c=this.e();d=this.a}break;case v:for(;d+g>c.length;)c=this.e({o:2});break;default:throw Error("invalid inflate mode");}if(q)c.set(e.subarray(a,a+g),d),d+=g,a+=g;else for(;g--;)c[d++]=e[a++];this.d=a;this.a=d;this.b=c;break;case 1:this.j(y,z);break;case 2:A(this);break;default:throw Error("unknown BTYPE: "+b);}}return this.m()};
11 | var B=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],C=q?new Uint16Array(B):B,D=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],E=q?new Uint16Array(D):D,F=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],G=q?new Uint8Array(F):F,H=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],I=q?new Uint16Array(H):H,K=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,
12 | 13],L=q?new Uint8Array(K):K,M=new (q?Uint8Array:Array)(288),N,O;N=0;for(O=M.length;N=N?8:255>=N?9:279>=N?7:8;var y=t(M),P=new (q?Uint8Array:Array)(30),Q,R;Q=0;for(R=P.length;Q=g)throw Error("input buffer is broken");a|=d[f++]<>>e;b.c=c-e;b.d=f;return h}
13 | function S(b,e){for(var a=b.f,c=b.c,d=b.input,f=b.d,g=d.length,h=e[0],k=e[1],m,r;c=g);)a|=d[f++]<>>16;b.f=a>>r;b.c=c-r;b.d=f;return m&65535}
14 | function A(b){function e(a,b,c){var e,d=this.p,f,g;for(g=0;gf)c>=d&&(this.a=c,a=this.e(),c=this.a),a[c++]=f;else{g=f-257;k=E[g];0=d&&(this.a=c,a=this.e(),c=this.a);for(;k--;)a[c]=a[c++-h]}for(;8<=this.c;)this.c-=8,this.d--;this.a=c};
16 | u.prototype.t=function(b,e){var a=this.b,c=this.a;this.n=b;for(var d=a.length,f,g,h,k;256!==(f=S(this,b));)if(256>f)c>=d&&(a=this.e(),d=a.length),a[c++]=f;else{g=f-257;k=E[g];0d&&(a=this.e(),d=a.length);for(;k--;)a[c]=a[c++-h]}for(;8<=this.c;)this.c-=8,this.d--;this.a=c};
17 | u.prototype.e=function(){var b=new (q?Uint8Array:Array)(this.a-32768),e=this.a-32768,a,c,d=this.b;if(q)b.set(d.subarray(32768,b.length));else{a=0;for(c=b.length;aa;++a)d[a]=d[e+a];this.a=32768;return d};
18 | u.prototype.v=function(b){var e,a=this.input.length/this.d+1|0,c,d,f,g=this.input,h=this.b;b&&("number"===typeof b.o&&(a=b.o),"number"===typeof b.r&&(a+=b.r));2>a?(c=(g.length-this.d)/this.n[2],f=258*(c/2)|0,d=fe&&(this.b.length=e),b=this.b);return this.buffer=b};p("Zlib.RawInflate",u);p("Zlib.RawInflate.prototype.decompress",u.prototype.u);var T={ADAPTIVE:v,BLOCK:w},U,V,W,X;if(Object.keys)U=Object.keys(T);else for(V in U=[],W=0,T)U[W++]=V;W=0;for(X=U.length;W 0.5 ? d / (2 - max - min) : d / (max + min);
48 | switch(max){
49 | case r: h = (g - b) / d + (g < b ? 6 : 0); break;
50 | case g: h = (b - r) / d + 2; break;
51 | case b: h = (r - g) / d + 4; break;
52 | }
53 | h /= 6;
54 | }
55 |
56 | return [h, s, l];
57 | }
58 |
59 | /**
60 | * Converts an HSL color value to RGB. Conversion formula
61 | * adapted from http://en.wikipedia.org/wiki/HSL_color_space.
62 | * Assumes h, s, and l are contained in the set [0, 1] and
63 | * returns r, g, and b in the set [0, 255].
64 | *
65 | * @param Number h The hue
66 | * @param Number s The saturation
67 | * @param Number l The lightness
68 | * @return Array The RGB representation
69 | */
70 | function hslToRgb(h, s, l){
71 | var r, g, b;
72 |
73 | if(s == 0){
74 | r = g = b = l; // achromatic
75 | }else{
76 | function hue2rgb(p, q, t){
77 | if(t < 0) t += 1;
78 | if(t > 1) t -= 1;
79 | if(t < 1/6) return p + (q - p) * 6 * t;
80 | if(t < 1/2) return q;
81 | if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
82 | return p;
83 | }
84 |
85 | var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
86 | var p = 2 * l - q;
87 | r = hue2rgb(p, q, h + 1/3);
88 | g = hue2rgb(p, q, h);
89 | b = hue2rgb(p, q, h - 1/3);
90 | }
91 |
92 | return [r * 255, g * 255, b * 255];
93 | }
94 |
95 | /**
96 | * Converts an RGB color value to HSV. Conversion formula
97 | * adapted from http://en.wikipedia.org/wiki/HSV_color_space.
98 | * Assumes r, g, and b are contained in the set [0, 255] and
99 | * returns h, s, and v in the set [0, 1].
100 | *
101 | * @param Number r The red color value
102 | * @param Number g The green color value
103 | * @param Number b The blue color value
104 | * @return Array The HSV representation
105 | */
106 | function rgbToHsv(r, g, b){
107 | r = r/255, g = g/255, b = b/255;
108 | var max = Math.max(r, g, b), min = Math.min(r, g, b);
109 | var h, s, v = max;
110 |
111 | var d = max - min;
112 | s = max == 0 ? 0 : d / max;
113 |
114 | if(max == min){
115 | h = 0; // achromatic
116 | }else{
117 | switch(max){
118 | case r: h = (g - b) / d + (g < b ? 6 : 0); break;
119 | case g: h = (b - r) / d + 2; break;
120 | case b: h = (r - g) / d + 4; break;
121 | }
122 | h /= 6;
123 | }
124 |
125 | return [h, s, v];
126 | }
127 |
128 | /**
129 | * Converts an HSV color value to RGB. Conversion formula
130 | * adapted from http://en.wikipedia.org/wiki/HSV_color_space.
131 | * Assumes h, s, and v are contained in the set [0, 1] and
132 | * returns r, g, and b in the set [0, 255].
133 | *
134 | * @param Number h The hue
135 | * @param Number s The saturation
136 | * @param Number v The value
137 | * @return Array The RGB representation
138 | */
139 | function hsvToRgb(h, s, v){
140 | var r, g, b;
141 |
142 | var i = Math.floor(h * 6);
143 | var f = h * 6 - i;
144 | var p = v * (1 - s);
145 | var q = v * (1 - f * s);
146 | var t = v * (1 - (1 - f) * s);
147 |
148 | switch(i % 6){
149 | case 0: r = v, g = t, b = p; break;
150 | case 1: r = q, g = v, b = p; break;
151 | case 2: r = p, g = v, b = t; break;
152 | case 3: r = p, g = q, b = v; break;
153 | case 4: r = t, g = p, b = v; break;
154 | case 5: r = v, g = p, b = q; break;
155 | }
156 |
157 | return [r * 255, g * 255, b * 255];
158 | }
159 | /**
160 | * Darken the hex color by amount ,amout is from 0 to 1
161 | * */
162 | function darkenHexColor(color, amount) {
163 |
164 | var rgb = hexToRgb(color);
165 | var hsl = rgbToHsl(rgb[0], rgb[1], rgb[2]);
166 | hsl[2] -= amount;
167 | rgb = hslToRgb(hsl[0], hsl[1], hsl[2]);
168 | return rgbToHex(rgb[0], rgb[1], rgb[2]);
169 | }
170 |
171 | function _toHex(num) {
172 | num = parseInt(num, 10);
173 | if (isNaN(num)) return "00";
174 | num = Math.max(0, Math.min(num, 255));
175 | return HEX_NUM.charAt((num - num%16) / 16)
176 | + HEX_NUM.charAt(num % 16);
177 | }
--------------------------------------------------------------------------------
/src/flax/game/Gunner.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 14-4-24.
3 | */
4 |
5 | flax._gunnerDefine = {
6 | camp:null,//Player or Enemy?
7 | _gunParam:null,//see flax.GunParam, remember the anchors, ["weapon1","weapon2"]
8 | targets:null,//the targets array of the enemy
9 | alwaysBind:true,//if the gun always bind to the anchor every frame
10 | _guns:null,
11 | _autoShooting:false,
12 | _waitingShoot:false,
13 | _auto:false,//if true, will auto shoot according to the gunParam
14 |
15 | onEnter:function()
16 | {
17 | this._super();
18 | this._guns = [];
19 | if(this._gunParam) this.setGunParam(this._gunParam);
20 | },
21 | onRecycle:function()
22 | {
23 | this._super();
24 | this.camp = null;
25 | this._gunParam = null;
26 | this.targets = null;
27 | this._guns = null;
28 | this._autoShooting = this._waitingShoot = this._auto = false;
29 | this.stopShoot();
30 | },
31 | getGunParam:function(){
32 | return this._gunParam;
33 | },
34 | setGunParam:function(param, gunAnchors)
35 | {
36 | this._gunParam = param;
37 | if(this.parent == null) return;
38 | if(!gunAnchors) gunAnchors = param.gunAnchors;
39 | if(gunAnchors == null){
40 | cc.log("Please set the gunAnchors param!");
41 | return;
42 | }
43 | var i = -1;
44 | var n = gunAnchors.length;
45 | var gunAnchor = null;
46 | var gun = null;
47 | while(++i < n)
48 | {
49 | gunAnchor = gunAnchors[i];
50 | gun = flax.Gun.create(this._gunParam);
51 | if(this.bindAnchor(gunAnchor, gun, this.alwaysBind)) {
52 | gun.owner = this;
53 | gun.name = gunAnchor;
54 | this[gunAnchor] = gun;
55 | this._guns.push(gun);
56 | }
57 | }
58 | if(this._waitingShoot){
59 | this.scheduleOnce(this.autoShoot, 0.1);
60 | }
61 | },
62 | shoot:function(){
63 | this._auto = false;
64 | this._doBeginShoot();
65 | },
66 | autoShoot:function(delay)
67 | {
68 | this._auto = true;
69 | if(this.parent == null || this._guns == null || this._guns.length == 0) {
70 | this._waitingShoot = true;
71 | return;
72 | }
73 | if(delay > 0){
74 | this.scheduleOnce(this._doBeginShoot, delay);
75 | }else{
76 | this._doBeginShoot();
77 | }
78 | this._autoShooting = true;
79 | this._waitingShoot = false;
80 | },
81 | /**
82 | * Set a target to aim to
83 | * */
84 | aimToTarget:function(target){
85 | if(!target || !target.parent || !target.visible) return;
86 | if(this.targets == null) this.targets = [target];
87 | else if(this.targets.indexOf(target) == -1) this.targets.push(target);
88 | var i = -1;
89 | var n = this._guns.length;
90 | var gun = null;
91 | while(++i < n)
92 | {
93 | gun = this._guns[i];
94 | gun.aimTarget = target;
95 | }
96 | },
97 | onAimingTarget:function(angle){
98 | //to be override
99 | },
100 | _doBeginShoot:function()
101 | {
102 | var i = -1;
103 | var n = this._guns.length;
104 | while(++i < n)
105 | {
106 | if(this._auto) this._guns[i].start();
107 | else this._guns[i].shootOnce();
108 | }
109 | },
110 | stopShoot:function()
111 | {
112 | this._autoShooting = false;
113 | if(this._guns == null || this._guns.length == 0) return;
114 | var i = -1;
115 | var n = this._guns.length;
116 | while(++i < n)
117 | {
118 | this._guns[i].end();
119 | }
120 | },
121 | upgradeGun:function(deltaParam, time)
122 | {
123 | var delta = this._deltaGunParam(deltaParam);
124 | if(!isNaN(time) && time > 0){
125 | this.scheduleOnce(function(){
126 | this._deltaGunParam(delta);
127 | }, time);
128 | }else{
129 | this._deltaGunParam(delta);
130 | }
131 | },
132 | _deltaGunParam:function(param)
133 | {
134 | if(this._guns.length == 0) return;
135 | var delta = {};
136 | var newValue = 0;
137 | for(var k in param){
138 | newValue = this._guns[0].param[k] + param[k];
139 | if(newValue <= 0) {
140 | delete param[k];
141 | continue;
142 | }
143 | delta[k] = -param[k];
144 | param[k] = newValue;
145 | }
146 | var i = this._guns.length;
147 | var gun = null;
148 | while(i--)
149 | {
150 | gun = this._guns[i];
151 | gun.updateParam(param);
152 | }
153 | return delta;
154 | },
155 | onDie:function()
156 | {
157 | this.stopShoot();
158 | flax.callModuleFunction(this, "onDie");
159 | if(this.ownerBody) this.ownerBody.destroy();
160 | else this.destroy();
161 | }
162 | };
163 |
164 | flax.Gunner = flax.Animator.extend(flax._gunnerDefine);
165 | //Avoid to advanced compile mode
166 | window['flax']['Gunner'] = flax.Gunner;
167 |
168 | flax.MCGunner = flax.MovieClip.extend(flax._gunnerDefine);
169 | //Avoid to advanced compile mode
170 | window['flax']['MCGunner'] = flax.MCGunner;
171 |
172 | flax.addModule(flax.Gunner, flax.HealthModule, false);
173 | flax.addModule(flax.MCGunner, flax.HealthModule, false);
174 |
175 | var _p = flax.Gunner.prototype;
176 | /** @expose */
177 | _p.onHit;
178 | /** @expose */
179 | _p.onDie;
180 | /** @expose */
181 | _p.gunParam;
182 | cc.defineGetterSetter(_p, "gunParam", _p.getGunParam, _p.setGunParam);
183 |
184 | _p = flax.MCGunner.prototype;
185 | /** @expose */
186 | _p.onHit;
187 | /** @expose */
188 | _p.onDie;
189 | /** @expose */
190 | _p.gunParam;
191 | cc.defineGetterSetter(_p, "gunParam", _p.getGunParam, _p.setGunParam);
192 |
193 | flax.Gunner.create = function(assetsFile, assetID)
194 | {
195 | var h = new flax.Gunner(assetsFile, assetID);
196 | h.clsName = "flax.Gunner";
197 | return h;
198 | };
199 |
200 | flax.MCGunner.create = function(assetsFile, assetID)
201 | {
202 | var h = new flax.MCGunner(assetsFile, assetID);
203 | h.clsName = "flax.MCGunner";
204 | return h;
205 | };
206 |
207 |
208 |
209 |
--------------------------------------------------------------------------------
/src/flax/game/LinkFinder.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 14-2-15.
3 | */
4 | EIGHT_DIRECT_VALUE = [[0,1],[0,-1],[-1,0],[1,0],[-1,1],[1,1],[1,-1],[-1,-1]];
5 | var LinkFinder = {};
6 | window['LinkFinder'] = LinkFinder;
7 | //the flax.TileMap to manage all the objects to link together
8 | LinkFinder.map = null;
9 | //an objects array, the linkage with these objects are unavailable
10 | LinkFinder.blocks = null;
11 | /**
12 | * Check if tx0,ty0 and tx1,ty1 are linked
13 | * */
14 | LinkFinder.findLink = function(tx0, ty0, tx1, ty1)
15 | {
16 | var link = null;
17 | if(tx0 == tx1 || ty0 == ty1) {
18 | link = LinkFinder._checkDirectLink(tx0, ty0, tx1, ty1);
19 | }else{
20 | link = LinkFinder._checkOneLink(tx0, ty0, tx1, ty1);
21 | }
22 | if(link == null)
23 | {
24 | link = LinkFinder._checkTwoLink(tx0, ty0, tx1, ty1);
25 | }
26 | return link;
27 | };
28 | LinkFinder.shuffle = function(useTween){
29 | var all = this.map.getAllObjects();
30 | var tiles = all.concat();
31 | var i = -1;
32 | if(this.blocks && this.blocks.length){
33 | tiles = [];
34 | while(++i < all.length){
35 | var a = all[i];
36 | if(this.blocks.indexOf(a) == -1){
37 | tiles.push(a);
38 | }
39 | }
40 | }
41 | flax.shuffleArray(tiles);
42 | i = -1;
43 | var halfCount = tiles.length/2;
44 | while(++i < halfCount){
45 | var a0 = tiles[i];
46 | var a1 = tiles[i + halfCount];
47 | // var tempPos = cc.p(a0.getPosition());
48 | var tempPos = a0.getPosition();
49 | if(useTween !== false){
50 | a0.runAction(cc.MoveTo.create(0.2, a1.getPosition()));
51 | a1.runAction(cc.MoveTo.create(0.2, tempPos));
52 | }else{
53 | a0.setPosition(a1.getPosition());
54 | a1.setPosition(tempPos);
55 | }
56 | }
57 | };
58 | /**
59 | * Check if the map is dead, dead means there is no link anymore, then tried to fix it
60 | * Return a available linked pair, null result means there is no link anymore and can't be fixed
61 | * */
62 | LinkFinder.findAvailableLink = function(useTween)
63 | {
64 | var tiles = this.map.getAllObjects();
65 | var count = tiles.length;
66 | if(count == 0) return null;
67 | var f0;
68 | var f1;
69 | var link = null;
70 | var sameTypes = [];
71 | var first = null;
72 | for(var i = 0; i< count -1; i++)
73 | {
74 | f0 = tiles[i];
75 | if(this.blocks && this.blocks.indexOf(f0) > -1) continue;
76 | var checkSameType = (sameTypes.length == 0);
77 | if(first == null) first = f0;
78 | for(var j = i + 1; j < count; j++)
79 | {
80 | f1 = tiles[j];
81 | if(this.blocks && this.blocks.indexOf(f1) > -1) continue;
82 | if(f1.assetID == f0.assetID) {
83 | if(LinkFinder.findLink(f0.tx, f0.ty, f1.tx, f1.ty)){
84 | return [f0, f1];
85 | }
86 | if(checkSameType) sameTypes.push(f1);
87 | }else if(checkSameType && link == null && LinkFinder.findLink(f0.tx, f0.ty, f1.tx, f1.ty)){
88 | link = f1;
89 | }
90 | }
91 | }
92 | if(sameTypes.length == 0) return null;
93 | var theLink = sameTypes[Math.floor(sameTypes.length*Math.random())];
94 | var tempPos = cc.p(theLink.getPosition());
95 | if(link == null) {
96 | var empty = this._findEmptyNeighbor(first.tx, first.ty);
97 | if(empty == null) throw "Dead map!!!!";
98 | tempPos = this.map.getTiledPosition(empty.x, empty.y);
99 | if(theLink.parent) tempPos = theLink.parent.convertToNodeSpace(tempPos);
100 | if(useTween === true){
101 | theLink.runAction(cc.MoveTo.create(0.2, tempPos));
102 | }else{
103 | theLink.setPosition(tempPos);
104 | }
105 | }else{
106 | if(useTween === true){
107 | theLink.runAction(cc.MoveTo.create(0.2, link.getPosition()));
108 | link.runAction(cc.MoveTo.create(0.2, tempPos));
109 | }else{
110 | theLink.setPosition(link.getPosition());
111 | link.setPosition(tempPos);
112 | }
113 | }
114 | return [first, theLink];
115 | };
116 | LinkFinder._findEmptyNeighbor = function(tx, ty){
117 | var result = null;
118 | for(var i = 0; i < 4; i++){
119 | var ds = EIGHT_DIRECT_VALUE[i];
120 | result = cc.p(tx + ds[0], ty + ds[1]);
121 | if(this.map.isEmptyTile(result.x, result.y)) return result;
122 | }
123 | return result;
124 | };
125 | LinkFinder._checkDirectLink = function(tx0, ty0, tx1, ty1)
126 | {
127 | if(tx0 == tx1 && ty0 == ty1) return null;
128 | if(tx0 == tx1)
129 | {
130 | var linked = true;
131 | var d = (ty1 - ty0 > 0) ? 1 : -1;
132 | var ty = ty0 + d;
133 | while(ty != ty1)
134 | {
135 | if(!this.map.isEmptyTile(tx0, ty)){
136 | linked = false;
137 | break;
138 | }
139 | ty += d;
140 | }
141 | if(linked) return [new cc.p(tx0, ty0), new cc.p(tx1, ty1)];
142 | }
143 | if(ty0 == ty1)
144 | {
145 | var linked = true;
146 | var d = (tx1 - tx0 > 0) ? 1 : -1;
147 | var tx = tx0 + d;
148 | while(tx != tx1)
149 | {
150 | if(!this.map.isEmptyTile(tx, ty0)){
151 | linked = false;
152 | break;
153 | }
154 | tx += d;
155 | }
156 | if(linked) return [new cc.p(tx0, ty0), new cc.p(tx1, ty1)];
157 | }
158 | return null;
159 | };
160 | LinkFinder._checkOneLink = function(tx0, ty0, tx1, ty1)
161 | {
162 | if(tx0 == tx1 || ty0 == ty1) return null;
163 | //corner1: tx0, ty1
164 | if(this.map.isEmptyTile(tx0, ty1)){
165 | var linked0 = LinkFinder._checkDirectLink(tx0, ty0, tx0, ty1);
166 | if(linked0) {
167 | var linked1 = LinkFinder._checkDirectLink(tx0, ty1, tx1, ty1);
168 | if(linked1) return [new cc.p(tx0, ty0), new cc.p(tx0, ty1), new cc.p(tx1, ty1)];
169 | }
170 | }
171 | //corner2: tx1, ty0
172 | if(this.map.isEmptyTile(tx1, ty0))
173 | {
174 | var linked0 = LinkFinder._checkDirectLink(tx0, ty0, tx1, ty0);
175 | if(linked0) {
176 | var linked1 = LinkFinder._checkDirectLink(tx1, ty0, tx1, ty1);
177 | if(linked1) {
178 | return [new cc.p(tx0, ty0), new cc.p(tx1, ty0), new cc.p(tx1, ty1)];
179 | }
180 | }
181 | }
182 | return null;
183 | };
184 | LinkFinder._checkTwoLink = function(tx0, ty0, tx1, ty1)
185 | {
186 | if(tx0 == tx1 && ty0 == ty1) return null;
187 | var dx = (tx1 - tx0) >= 0 ? 1 : -1;
188 | var dy = (ty1 - ty0) >= 0 ? 1 : -1;
189 | var link = LinkFinder._twoLinkSearch(tx0, ty0, tx1, ty1, dx, dy);
190 | if(link == null) link = LinkFinder._twoLinkSearch(tx0, ty0, tx1, ty1, -dx, -dy);
191 | if(link != null) link.unshift(new cc.p(tx0, ty0));
192 | return link;
193 | };
194 | LinkFinder._twoLinkSearch = function(tx0, ty0, tx1, ty1, dx, dy)
195 | {
196 | var link = null;
197 | var tx = tx0 + dx;
198 | var ty = ty0 + dy;
199 | var xOver = false;
200 | var yOver = false;
201 | while(!xOver || !yOver)
202 | {
203 | if(!xOver)
204 | {
205 | xOver = !this.map.isEmptyTile(tx, ty0);
206 | if(!xOver){
207 | link = LinkFinder._checkOneLink(tx, ty0, tx1, ty1);
208 | if(link != null) break;
209 | tx += dx;
210 | }
211 | }
212 | if(!yOver)
213 | {
214 | yOver = !this.map.isEmptyTile(tx0, ty);
215 | if(!yOver){
216 | link = LinkFinder._checkOneLink(tx0, ty, tx1, ty1);
217 | if(link != null) break;
218 | ty += dy;
219 | }
220 | }
221 | }
222 | return link;
223 | };
--------------------------------------------------------------------------------
/src/flax/game/ObjectPool.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 14-2-22.
3 | */
4 |
5 | flax.ObjectPool = cc.Class.extend({
6 | maxCount:100,
7 | _clsName:null,
8 | _cls:null,
9 | _assetsFile:null,
10 | _pool:null,
11 | _extraID:"",
12 |
13 | init:function(assetsFile, clsName, maxCount)
14 | {
15 | if(this._assetsFile && this._cls){
16 | cc.log("The pool has been inited with cls: "+this._cls);
17 | return false;
18 | }
19 | this._clsName = clsName;
20 | this._cls = flax.nameToObject(clsName);
21 | if(this._cls == null){
22 | cc.log("There is no class named: "+clsName);
23 | return false;
24 | }
25 | this._assetsFile = assetsFile;
26 | this._pool = [];
27 | if(maxCount !== undefined) this.maxCount = maxCount;
28 | return true;
29 | },
30 | fetch:function(assetID, parent, params)
31 | {
32 | if(assetID == null){
33 | cc.log("Please give me a assetID to fetch a object!");
34 | return null;
35 | }
36 | var obj = null;
37 | if(this._pool.length > 0){
38 | obj = this._pool.shift();
39 | obj.__fromPool = true;
40 | obj.setSource(this._assetsFile, assetID);
41 | }else{
42 | if(this._cls.create) obj = this._cls.create(this._assetsFile, assetID);
43 | else obj = new this._cls(this._assetsFile, assetID);
44 | }
45 |
46 | obj.__pool__id__ = this._extraID;
47 | obj.clsName = this._clsName;
48 | obj._destroyed = false;
49 | obj.autoRecycle = true;
50 | obj.visible = true;
51 |
52 | //to fix the zIndex bug
53 | if(params){
54 | if(typeof params.zIndex === "undefined") params.zIndex = 0;
55 | }else{
56 | params = {zIndex:0};
57 | }
58 | obj.attr(params);
59 | if(parent) parent.addChild(obj);
60 | // cc.log("fetch: "+obj.assetID);
61 | return obj;
62 | },
63 | recycle:function(object)
64 | {
65 | if(!(object instanceof this._cls)){
66 | cc.log("The object to recycle is not the same type with this pool: "+this._clsName);
67 | return;
68 | }
69 | if(this._pool.length < this.maxCount){
70 | // cc.log("recycle: "+object.assetID);
71 | object.onRecycle&&object.onRecycle();
72 | object.retain&&object.retain();
73 | this._pool.push(object);
74 | }
75 | },
76 | release:function()
77 | {
78 | var i = this._pool.length;
79 | while(i--){
80 | this._pool[i].release&&this._pool[i].release();
81 | }
82 | this._pool.length = 0;
83 | }
84 | });
85 |
86 | flax.ObjectPool.all = {};
87 |
88 | flax.ObjectPool.create = function(assetsFile, clsName, maxCount)
89 | {
90 | var pool = new flax.ObjectPool();
91 | if(pool.init(assetsFile, clsName, maxCount)) {
92 | return pool;
93 | }
94 | return null;
95 | };
96 | flax.ObjectPool.get = function(assetsFile, clsName, id)
97 | {
98 | if(clsName == null) clsName = "flax.Animator";
99 | if(id == null) id = "";
100 | var key = assetsFile+clsName+id;
101 | var pool = flax.ObjectPool.all[key];
102 | if(pool == null){
103 | pool = flax.ObjectPool.create(assetsFile, clsName);
104 | pool._extraID = id;
105 | flax.ObjectPool.all[key] = pool;
106 | }
107 | return pool;
108 | };
109 |
110 | flax.ObjectPool.release = function()
111 | {
112 | for(var k in flax.ObjectPool.all){
113 | flax.ObjectPool.all[k].release();
114 | delete flax.ObjectPool.all[k];
115 | }
116 | };
117 |
118 |
--------------------------------------------------------------------------------
/src/flax/game/Preloader.js:
--------------------------------------------------------------------------------
1 |
2 | flax._preloader = {
3 | resources:null,
4 | _label : null,
5 | _logo:null,
6 | _inited:false,
7 | /**
8 | * init with resources
9 | * @param {Array} resources
10 | * @param {Function|String} cb
11 | */
12 | initWithResources: function (resources, cb) {
13 | this.init();
14 | if(typeof resources == "string")
15 | resources = [resources];
16 | this.resources = resources || [];
17 | this.cb = cb;
18 | },
19 | init : function(){
20 | if(this._inited) return;
21 | this._inited = true;
22 |
23 | var self = this;
24 | var winSize = cc.director.getWinSize();
25 |
26 | if(this instanceof cc.Layer){
27 | var back = new cc.LayerColor(cc.color(0, 0, 0, 100));
28 | this.addChild(back, 0);
29 | }
30 | //logo
31 | var centerPos = cc.p(winSize.width / 2, winSize.height / 2);
32 |
33 | //logo
34 | var loadingImg = cc.game.config["loading"];
35 | if(loadingImg && flax.isImageFile(loadingImg)){
36 | cc.loader.load(loadingImg, function(){
37 | self._logo = new cc.Sprite(loadingImg);
38 | self._logo.setPosition(centerPos);
39 | self.addChild(self._logo, 10);
40 | if(!cc.sys.isNative){
41 | var fontSize = 16*(1 + self._logo.width/200);
42 | self.createLabel(cc.pSub(centerPos, cc.p(0, self._logo.height/2 + fontSize*0.6)), fontSize);
43 | self.logoClick();
44 | }
45 | })
46 | }else{
47 | self.createLabel(centerPos);
48 | }
49 | },
50 | createLabel:function(pos, fontSize){
51 | var label = this._label = new cc.LabelTTF("Loading...", "Arial", fontSize || 18);
52 | label.enableStroke(cc.color(51, 51, 51), 2);
53 | label.setColor(cc.color(255, 255, 255));
54 | label.setPosition(pos);
55 | this.addChild(label, 10);
56 | },
57 | logoClick:function(){
58 | //click logo to go
59 | var logo = this._logo;
60 | var listener = cc.EventListener.create({
61 | event: cc.EventListener.TOUCH_ONE_BY_ONE,
62 | swallowTouches: false,
63 | onTouchBegan:function(touch, event)
64 | {
65 | if(cc.rectContainsPoint(flax.getRect(logo, true), touch.getLocation())){
66 | flax.goHomeUrl();
67 | return true;
68 | }
69 | return false;
70 | }
71 | });
72 | cc.eventManager.addListener(listener, this._logo);
73 | },
74 | onEnter: function () {
75 | var self = this;
76 | cc.Node.prototype.onEnter.call(self);
77 | if(this.resources) self.schedule(self._startLoading, 0.3);
78 | },
79 | _startLoading: function () {
80 | var self = this;
81 | self.unschedule(self._startLoading);
82 | var res = self.resources;
83 | cc.loader.load(res,
84 | function (result, count, loadedCount) {
85 | if(self._label == null) return;
86 | self._showProgress("Loading: ", count, loadedCount);
87 | }, function () {
88 | if (self.cb)
89 | self.cb();
90 | });
91 | },
92 | _showProgress:function(text, count, loadedCount)
93 | {
94 | if(!this._label) return;
95 | if(loadedCount != null) this._label.setString(text + (loadedCount + 1) + "/" + count);
96 | else {
97 | // var percent = (loadedCount / count * 100) | 0;
98 | // percent = Math.min(percent, 100);
99 | this._label.setString(text + count + "%");
100 | }
101 | }
102 | };
103 |
104 | flax.Preloader = cc.Scene.extend(flax._preloader);
105 | flax.ResPreloader = cc.Layer.extend(flax._preloader);
106 | //Avoid to advanced compile mode
107 | window['flax']['Preloader'] = flax.Preloader;
108 | window['flax']['ResPreloader'] = flax.ResPreloader;
109 |
--------------------------------------------------------------------------------
/src/flax/game/ScrollPane.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 14-6-6.
3 | */
4 |
5 | flax._scrollPaneDefine = {
6 | _viewRect:null,
7 | onEnter:function(){
8 | this._super();
9 | //todo, maybe true
10 | this._viewRect = this.getCollider("view").getRect(true);
11 | if(!this._viewRect) {
12 | cc.log("If you want me scrollable, please set collider__view for me!");
13 | return;
14 | }
15 | flax.inputManager.addListener(null, this._startDrag, InputType.press, this);
16 | //todo, mask the content
17 | // var stencil = cc.DrawNode.create();
18 | // var rectangle = [cc.p(0, 0),cc.p(this._viewRect.width, 0),cc.p(this._viewRect.width, this._viewRect.height),cc.p(0, this._viewRect.height)];
19 | // var color = cc.color(255, 255, 255, 100);
20 | // stencil.drawPoly(rectangle, color, 1, color);
21 | //// this.parent.addChild(stencil, 10000);
22 | // stencil.setPosition(this._viewRect.x, this._viewRect.y);
23 | // var mask = cc.ClippingNode.create(stencil);
24 | // mask.addChild(this);
25 | },
26 | /**
27 | * Scroll the pane to make the target in the screen center
28 | * @param {sprite || point} target the sprite or the position in this pane
29 | * @param {number} time the duration to scroll to
30 | * */
31 | scrollToCenter:function(target, time){
32 | var pos0 = cc.visibleRect.center;
33 | pos0 = this.parent.convertToNodeSpace(pos0);
34 | var pos = this.convertToWorldSpace( target.getPosition ? target.getPosition() : target);
35 | pos = this.parent.convertToNodeSpace(pos);
36 | var delta = cc.pSub(pos0, pos);
37 | var x = this.x + delta.x;
38 | var y = this.y + delta.y;
39 | var newPos = this._validatePos(x, y);
40 | if(time > 0){
41 | this.runAction(cc.MoveTo.create(time, newPos));
42 | }else{
43 | this.setPosition(newPos);
44 | }
45 | },
46 | _startDrag:function(touch, event){
47 | this.scheduleOnce(function(){
48 | flax.inputManager.addListener(null, this._drag, InputType.move,this);
49 | flax.inputManager.addListener(null, this._stopDrag, InputType.up, this);
50 | },0.01);
51 | },
52 | _drag:function(touch, event){
53 | var delta = touch.getDelta();
54 | //if the viewRect is larger than the content itself, then do nothing
55 | if(this._viewRect.width >= this.width) delta.x = 0;
56 | if(this._viewRect.height >= this.height) delta.y = 0;
57 |
58 | var x = this.x + delta.x;
59 | var y = this.y + delta.y;
60 | var newPos = this._validatePos(x, y);
61 | this.x = newPos.x;
62 | this.y = newPos.y;
63 | },
64 | _stopDrag:function(touch, event){
65 | flax.inputManager.removeListener(null, this._drag, InputType.move);
66 | flax.inputManager.removeListener(null, this._stopDrag, InputType.up);
67 | },
68 | _validatePos:function(x, y){
69 | x = Math.max(this._viewRect.x + this._viewRect.width - this.width, x);
70 | x = Math.min(this._viewRect.x, x);
71 |
72 | y = Math.max(this._viewRect.y + this._viewRect.height - this.height, y);
73 | y = Math.min(this._viewRect.y, y);
74 |
75 | return cc.p(x, y);
76 | }
77 | };
78 |
79 | flax.ScrollPane = flax.Animator.extend(flax._scrollPaneDefine);
80 | flax.ScrollPane.create = function(assetsFile, assetID){
81 | var s = new flax.ScrollPane(assetsFile, assetID);
82 | return s;
83 | };
84 |
85 | //Avoid to advanced compile mode
86 | window['flax']['ScrollPane'] = flax.ScrollPane;
87 |
88 | flax.MCScrollPane = flax.MovieClip.extend(flax._scrollPaneDefine);
89 | flax.MCScrollPane.create = function(assetsFile, assetID){
90 | var s = new flax.MCScrollPane(assetsFile, assetID);
91 | return s;
92 | };
93 |
94 | //Avoid to advanced compile mode
95 | window['flax']['MCScrollPane'] = flax.MCScrollPane;
96 |
--------------------------------------------------------------------------------
/src/flax/game/ScrollingBG.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 14-2-27.
3 | */
4 |
5 | flax.ScrollingBG = cc.Node.extend({
6 | name:null,
7 | onScrolledOver:null,
8 | _loop:true,
9 | _bg0:null,
10 | _bg1:null,
11 | _sources:null,
12 | _scrollingIndex:0,
13 | _scrolling:false,
14 | _paused:false,
15 | _speedX:0,
16 | _speedY:0,
17 | _d:1,
18 | _size:null,
19 | _x0:0,
20 | _y0:0,
21 | ctor:function(source, assetID, isTiled)
22 | {
23 | this._super();
24 | this._sources = [];
25 | this.onScrolledOver = new signals.Signal();
26 | if(source){
27 | this.addSource(source, assetID, isTiled);
28 | }
29 | },
30 | onExit:function()
31 | {
32 | this._super();
33 | this.onScrolledOver.removeAll();
34 | },
35 | addSource:function(source, assetID, isTile)
36 | {
37 | this._sources.push({source: source, assetID: assetID, isTile:isTile});
38 | if(this._bg0 == null){
39 | this._bg0 = this._createNextBG();
40 | }
41 | },
42 | _createNextBG:function()
43 | {
44 | if(this._scrollingIndex > this._sources.length - 1){
45 | this._scrollingIndex = 0;
46 | }
47 | var bgData = this._sources[this._scrollingIndex];
48 | this._scrollingIndex ++;
49 |
50 | var bg = null;
51 | //If it's a custom display
52 | if(bgData.assetID != null){
53 | if(bgData.isTile !== true){
54 | bg = flax.assetsManager.createDisplay(bgData.source, bgData.assetID, null, true);
55 | }else{
56 | bg = new flax.TiledImage(bgData.source, bgData.assetID);
57 | }
58 | }else if(bgData.source){
59 | //if it's a FlaxSprite
60 | if(flax.isFlaxDisplay(bgData.source)){
61 | //todo, JSB Invalid native object error!
62 | if(bgData.source.parent) bgData.source.parent.addChild(this, bgData.source.zIndex);
63 | this.name = bgData.source.name;
64 | if(this.parent) this.parent[this.name] = this;
65 | this.setPosition(bgData.source.getPosition());
66 | bg = flax.assetsManager.cloneDisplay(bgData.source);
67 | bgData.source.removeFromParent();
68 | }
69 | //If it's a image
70 | else if(flax.isImageFile(bgData.source)){
71 | bg = new cc.Sprite(bgData.source);
72 | }else {
73 | throw "Not supported source type!";
74 | }
75 | }else{
76 | throw "Arguments is not valid!"
77 | }
78 | bg.setAnchorPoint(0, 0);
79 | this.addChild(bg);
80 |
81 | if(this._size == null){
82 | this._size = bg.getContentSize();
83 | this.setContentSize(this._size);
84 | }
85 |
86 | return bg;
87 | },
88 | reset:function()
89 | {
90 | this._paused = false;
91 | if(!this._scrolling) return;
92 | this._scrolling = false;
93 | this._speedX = this._speedY = 0;
94 |
95 | if(this._bg0.destroy) this._bg0.destroy();
96 | else this._bg0.removeFromParent();
97 | this._bg0 = null;
98 |
99 | if(this._bg1.destroy) this._bg1.destroy();
100 | else this._bg1.removeFromParent();
101 | this._bg1 = null;
102 |
103 | this._scrollingIndex = 0;
104 | if(this._bg0 == null) this._bg0 = this._createNextBG();
105 | this._bg0.setPosition(this._x0, this._y0);
106 | this.unscheduleUpdate();
107 | },
108 | startXScroll:function(speed, loop)
109 | {
110 | if(speed == 0 || this._bg0 == null) return;
111 | if(this._scrolling) return;
112 | this._scrolling = true;
113 | this._loop = loop !== false;
114 | this._speedX = speed;
115 | this._speedY = 0;
116 | this._d = (this._speedX > 0) ? 1: -1;
117 | this._resetScroll();
118 | this.scheduleUpdate();
119 | },
120 | startYScroll:function(speed, loop)
121 | {
122 | if(speed == 0 || this._bg0 == null) return;
123 | if(this._scrolling) return;
124 | this._scrolling = true;
125 | this._loop = loop !== false;
126 | this._speedY = speed;
127 | this._speedX = 0;
128 | this._d = (this._speedY > 0) ? 1: -1;
129 | this._resetScroll();
130 | this.scheduleUpdate();
131 | },
132 | pauseScroll:function()
133 | {
134 | if(!this._scrolling) return;
135 | if(this._paused) return;
136 | this._paused = true;
137 | this.unscheduleUpdate();
138 | },
139 | resumeScroll:function()
140 | {
141 | if(!this._scrolling) return;
142 | if(!this._paused) return;
143 | this._paused = false;
144 | this.scheduleUpdate();
145 | },
146 | _resetScroll:function()
147 | {
148 | this._bg0.setPosition(this._x0, this._y0);
149 | if(this._bg1 == null) this._bg1 = this._createNextBG();
150 | (this._speedX != 0) ? this._bg1.x = -this._d*(this._size.width - 1) : this._bg1.y = -this._d*(this._size.height - 1);
151 | },
152 | update:function(delta)
153 | {
154 | if(this._size.width*this._size.height == 0) {
155 | this._size = this._bg0.getContentSize();
156 | if(this._size.width*this._size.height != 0){
157 | this.setContentSize(this._size);
158 | this._resetScroll();
159 | }
160 | return;
161 | }
162 | var needReset = false;
163 | if(this._speedX != 0){
164 | var dx = this._speedX*delta;
165 | this._bg0.x += dx;
166 | this._bg1.x += dx;
167 | var dist = this._size.width - this._bg0.x*this._d;
168 | if(dist <= 0){
169 | this._bg0.x += this._d*dist;
170 | this._bg1.x += this._d*dist;
171 | needReset = true;
172 | }
173 | }else if(this._speedY != 0){
174 | var dy = this._speedY*delta;
175 | this._bg0.y += dy;
176 | this._bg1.y += dy;
177 | var dist = this._size.height - this._bg0.y*this._d;
178 | if(dist <= 0){
179 | this._bg0.y += this._d*dist;
180 | this._bg1.y += this._d*dist;
181 | needReset = true;
182 | }
183 | }
184 | if(needReset){
185 | if(!this._loop && this._scrollingIndex > this._sources.length - 1){
186 | this.onScrolledOver.dispatch();
187 | this.pauseScroll();
188 | return;
189 | }
190 | //todo, performance improve by reuse the bg?
191 | if(this._bg0.destroy) this._bg0.destroy();
192 | else this._bg0.removeFromParent();
193 | this._bg0 = this._bg1;
194 | this._bg1 = this._createNextBG();
195 | this._resetScroll();
196 | }
197 | },
198 | getRect:function(){
199 | if(this._size.width*this._size.height == 0) {
200 | this._size = this._bg0.getContentSize();
201 | if(this._size.width*this._size.height != 0){
202 | this.setContentSize(this._size);
203 | }
204 | }
205 | return cc.rect(0, 0, this._size.width, this._size.height);
206 | }
207 | });
208 |
209 | flax.ScrollingBG.create = function(source, assetID, isTiled)
210 | {
211 | var bg = new flax.ScrollingBG(source, assetID, isTiled);
212 | return bg;
213 | };
--------------------------------------------------------------------------------
/src/flax/game/SoundButton.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-5-7.
3 | */
4 |
5 | flax._soundButton = {
6 | onEnter:function()
7 | {
8 | this._super();
9 | this.setState(flax.getSoundEnabled() ? ButtonState.UP : ButtonState.SELECTED);
10 | },
11 | _onClick:function(touch, event)
12 | {
13 | this._super(touch, event);
14 | flax.setSoundEnabled(!this.isSelected());
15 | }
16 | }
17 |
18 | flax.SimpleSoundButton = flax.SimpleButton.extend(flax._soundButton);
19 |
20 | flax.SoundButton = flax.Button.extend(flax._soundButton);
--------------------------------------------------------------------------------
/src/flax/game/TiledImage.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 14-2-21.
3 | */
4 | /**
5 | * Layer.bake maybe a choice for good performance
6 | * */
7 | flax.TiledImage = cc.SpriteBatchNode.extend({
8 | tileMap:null,
9 | tileWidthOffset: 0,
10 | tileHeightOffset:0,
11 | assetsFile:null,
12 | assetID:null,
13 | _mapWidth:0,
14 | _mapHeight:0,
15 |
16 | ctor:function(assetsFile, assetID, minWidth, minHeight)
17 | {
18 | var imgFile = cc.path.changeBasename(assetsFile, ".png");
19 | cc.SpriteBatchNode.prototype.ctor.call(this, imgFile);
20 | this.tileMap = new flax.TileMap();
21 | this.setTileSource(assetsFile, assetID);
22 | if(!minWidth) minWidth = cc.visibleRect.width;
23 | if(!minHeight) minHeight = cc.visibleRect.height;
24 | this.setSize(minWidth, minHeight);
25 | },
26 | setTileSource:function(assetsFile, assetID)
27 | {
28 | if(this.assetsFile == assetsFile && this.assetID == assetID) return;
29 | this.assetsFile = assetsFile;
30 | this.assetID = assetID;
31 |
32 | var tile = flax.assetsManager.createDisplay(this.assetsFile, this.assetID);
33 | var size = tile.getContentSize();
34 | this.tileMap.init(size.width + this.tileWidthOffset, size.height + this.tileHeightOffset);
35 |
36 | if(this._mapWidth * this._mapHeight > 0) {
37 | if(this.getChildrenCount() > 0){
38 | this._updateTileImg();
39 | }
40 | this._updateSize();
41 | }
42 | },
43 | /**
44 | * todo, there is issue when randomly change the size
45 | * */
46 | setSize:function(w, h)
47 | {
48 | if(w == this._mapWidth && h == this._mapHeight) return;
49 | this._mapWidth = w;
50 | this._mapHeight = h;
51 | if(this.assetsFile) {
52 | this._updateSize();
53 | }
54 | },
55 | _updateTileImg:function()
56 | {
57 | var child = null;
58 | var num = this.getChildrenCount();
59 | var i = -1;
60 | while(++i < num)
61 | {
62 | child = this.children[i];
63 | child.setSource(this.assetsFile, this.assetID);
64 | this.tileMap.snapToTile(child, child.tx, child.ty);
65 | }
66 | },
67 | _updateSize:function()
68 | {
69 | var objs = this.tileMap.setMapSize(this._mapWidth, this._mapHeight, true);
70 | var i;
71 | var n = objs[0].length;
72 | if(n > 0) {
73 | var tile;
74 | i = -1;
75 | while(++i < n){
76 | //remove the tiles
77 | tile = objs[0][i];
78 | if(tile.destroy) tile.destroy();
79 | else tile.removeFromParent();
80 | }
81 | }
82 | n = objs[1].length;
83 | if(n > 0) {
84 | i = -1;
85 | while(++i < n){
86 | this._createTile(objs[1][i][0], objs[1][i][1]);
87 | }
88 | }
89 | this.setContentSize(this.tileMap.getMapSizePixel());
90 | },
91 | _createTile:function(i, j)
92 | {
93 | var tile = flax.assetsManager.createDisplay(this.assetsFile, this.assetID, {parent: this}, true);
94 | tile.setAnchorPoint(0.5, 0.5);
95 | this.tileMap.snapToTile(tile, i, j, true);
96 | return tile;
97 | }
98 | });
--------------------------------------------------------------------------------
/src/flax/game/UserData.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 14-11-19.
3 | */
4 | flax.userData = {
5 | // gold:100,
6 | // levelStars:[],
7 | // powerups:[0,0,0,0]
8 | };
9 |
10 | flax.fetchUserData = function(defaultValue) {
11 | if(defaultValue) flax.userData = defaultValue;
12 | var data = null;
13 | try{
14 | data = cc.sys.localStorage.getItem(cc.game.config["gameId"]);
15 | if(data) data = JSON.parse(data);
16 | }catch(e){
17 | cc.log("Fetch UserData Error: "+ e.name);
18 | }
19 | if(data) flax.copyProperties(data, flax.userData);
20 | // else if(defaultValue) flax.userData = defaultValue;
21 | if(!flax.userData) flax.userData = {};
22 | };
23 |
24 | flax.saveUserData = function() {
25 | if(!flax.userData) flax.userData = {};
26 | try{
27 | cc.sys.localStorage.setItem(cc.game.config["gameId"], JSON.stringify(flax.userData));
28 | }catch (e){
29 | cc.log("Save UserData Error: "+ e.name);
30 | }
31 | };
--------------------------------------------------------------------------------
/src/flax/module/EnemyWaveModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 14-7-11.
3 | */
4 | /**
5 | * var waves = [{types:["enemy1","enemy2"],count:5,interval:[3,5],gap:5},
6 | * {types:["enemy1","enemy2"],count:5,interval:[3,5],gap:5},
7 | * {types:["enemy1","enemy2"],count:5,interval:[3,5],gap:5}
8 | * ...]
9 | * Set waves and waveAssetJson, if need, override the _doCreateEnemy function
10 | * */
11 | flax.EnemyWaveModule = {
12 | waveAssetJson:null,
13 | waves:null,
14 | onWaveBegin:null,
15 | onEnemyIn:null,
16 | onWaveOver:null,
17 | batchCanvas:null,
18 | currentWave:-1,
19 | totalWaves:0,
20 | wavePaused:true,
21 | waveOver:false,
22 | _waveDefine:null,
23 | _enemyCount:0,
24 | _firstRun:true,
25 | onEnter:function()
26 | {
27 | this.totalWaves = this.waves.length;
28 | this.onWaveBegin = new signals.Signal();
29 | this.onEnemyIn = new signals.Signal();
30 | this.onWaveOver = new signals.Signal();
31 | if(!this.wavePaused){
32 | this.nextWave();
33 | }
34 | },
35 | onExit:function(){
36 | this.onWaveBegin.removeAll();
37 | this.onEnemyIn.removeAll();
38 | this.onWaveOver.removeAll();
39 | },
40 | startWave:function()
41 | {
42 | if(!this.wavePaused) return;
43 | this.wavePaused = false;
44 | if(this._firstRun) this.nextWave();
45 | else this._createWaveEnemy();
46 | this._firstRun = false;
47 | },
48 | stopWave:function()
49 | {
50 | if(this.wavePaused) return;
51 | this.wavePaused = true;
52 | },
53 | nextWave:function()
54 | {
55 | if(this.waveOver || this.wavePaused) return;
56 | this._enemyCount = 0;
57 | this.currentWave++;
58 | this._waveDefine = this.waves[this.currentWave];
59 | this._createWaveEnemy();
60 | this.onWaveBegin.dispatch();
61 | },
62 | _createWaveEnemy:function()
63 | {
64 | if(this.waveOver || this.wavePaused) return;
65 | var assetID = flax.getRandomInArray(this._waveDefine.types);
66 | var enemy = this._doCreateEnemy(assetID);
67 | this.onEnemyIn.dispatch(enemy);
68 | if(++this._enemyCount < this._waveDefine.count){
69 | var interval = flax.randInt(parseInt(this._waveDefine.interval[0]), parseInt(this._waveDefine.interval[1]));
70 | this.scheduleOnce(function(){
71 | this._createWaveEnemy();
72 | },interval);
73 | }else if(this.currentWave == this.totalWaves - 1){
74 | this.waveOver = true;
75 | this.onWaveOver.dispatch();
76 | }else{
77 | this.nextWave();
78 | }
79 | },
80 | _doCreateEnemy:function(assetID){
81 | if(this.waveAssetJson) flax.assetsManager.createDisplay(this.waveAssetJson, assetID, {parent: this.batchCanvas, x: this.x, y: this.y}, true);
82 | //override this function yourself
83 | }
84 | };
--------------------------------------------------------------------------------
/src/flax/module/HealthModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 14-7-10.
3 | */
4 | flax.HealthModule = {
5 | maxHealth:100,
6 | health:100,
7 | hurtable:true,
8 | dead:false,
9 | ownerBody:null,//the body to be hurted, when health == 0, the body will disappear, default body is the gunner itself
10 | onEnter:function(){
11 | this.health = this.maxHealth;
12 | this.dead = false;
13 | },
14 | onExit:function(){
15 | },
16 | onHit:function(bullet)
17 | {
18 | if(!this.hurtable) return false;
19 | if(this.dead) return true;
20 | this.health -= bullet.damage;
21 | if(this.health <= 0) {
22 | this.dead = true;
23 | this.health = 0;
24 | this.onDie();
25 | return true;
26 | }
27 | return false;
28 | },
29 | onDie:function()
30 | {
31 | if(this.ownerBody) this.ownerBody.destroy();
32 | else this.destroy();
33 | }
34 | };
--------------------------------------------------------------------------------
/src/flax/module/MoveModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-4-17.
3 | */
4 |
5 | flax.MoveModule = {
6 | gravityOnMove:null,
7 | destroyWhenReach:false,
8 | destroyWhenOutofStage:false,
9 | moveSpeed:null,
10 | moveAcc:null,
11 | restrainRect:null,
12 | inRandom:false,
13 | _moveSpeedLen:0,
14 | _targetPos:null,
15 | _inMoving:false,
16 | _callBack:null,
17 | _callContext:null,
18 |
19 | onEnter:function(){
20 | },
21 | onExit:function(){
22 | this.destroyWhenReach = false;
23 | this.destroyWhenOutofStage = false;
24 | this.gravityOnMove = null;
25 | this.restrainRect = null;
26 | this.inRandom = false;
27 | this._inMoving = false;
28 | },
29 | /**
30 | * Move to a new position within duration time
31 | * Note: If you use cc.moveTo in JSB, the setPosition function in js can not be called, use this instead of
32 | * */
33 | moveTo:function(pos, duration, callBack, callContext) {
34 | this.inRandom = false;
35 | this._targetPos = pos;
36 | this._callBack = callBack;
37 | this._callContext = callContext;
38 | var dis = cc.pSub(pos, this.getPosition());
39 | if(cc.pLength(dis) < 1 || !duration || duration <= 0){
40 | this.scheduleOnce(this._moveOver, 0.01);
41 | return;
42 | }
43 | this.moveSpeed = cc.pMult(dis, 1.0 / duration);
44 | this._moveSpeedLen = cc.pLength(this.moveSpeed);
45 | this.resumeMove();
46 | },
47 | /**
48 | * Move to a new position with speed
49 | * Note: If you use cc.moveTo in JSB, the setPosition function in js can not be called, use this instead of
50 | * */
51 | moveToBySpeed:function(pos, speed, callBack, callContext) {
52 | this.inRandom = false;
53 | this._targetPos = pos;
54 | this._callBack = callBack;
55 | this._callContext = callContext;
56 | var dis = cc.pSub(pos, this.getPosition());
57 | var len = cc.pLength(dis);
58 | if(len < 1){
59 | this.scheduleOnce(this._moveOver, 0.01);
60 | return;
61 | }
62 | this.moveSpeed = cc.pMult(dis, speed / len);
63 | this._moveSpeedLen = cc.pLength(this.moveSpeed);
64 | this.resumeMove();
65 | },
66 | /**
67 | * Just move forward with the speed (and the direction)
68 | * @speed {Point|Number} speed If its point, then move on x direction on .x speed and y direction on .y speed
69 | * @direction {Number} direction If speed is a number, then move on this direction(degree angle)
70 | * */
71 | moveBySpeed:function(speed, direction)
72 | {
73 | this._targetPos = null;
74 | this._callBack = null;
75 | this.inRandom = false;
76 |
77 | if(typeof speed === "object"){
78 | this.moveSpeed = speed;
79 | }else{
80 | this.moveSpeed = flax.getPointOnCircle(cc.p(), speed, direction);
81 | }
82 | this.resumeMove();
83 | },
84 | moveRandomly:function(speed, direction, restrainRect)
85 | {
86 | this.restrainRect = restrainRect || flax.stageRect;
87 | this.moveBySpeed(speed, direction || 360*Math.random());
88 | this.inRandom = direction == null;
89 | },
90 | pauseMove:function()
91 | {
92 | if(this._inMoving){
93 | this.unschedule(this._doMove);
94 | this._inMoving = false;
95 | }
96 | },
97 | resumeMove:function()
98 | {
99 | if(this._inMoving) return;
100 | this._inMoving = true;
101 | this.schedule(this._doMove, flax.frameInterval, cc.REPEAT_FOREVER);
102 | },
103 | stopMove:function()
104 | {
105 | if(this._inMoving){
106 | this._targetPos = this.moveSpeed = null;
107 | this._inMoving = false;
108 | this._callBack = null;
109 | this.restrainRect = null;
110 | this.inRandom = false;
111 | this.unschedule(this._doMove);
112 | }
113 | },
114 | _doMove:function(delta)
115 | {
116 | var pos = this.getPosition();
117 | var dis = this._targetPos ? cc.pDistance(pos, this._targetPos) : Number.maxValue;
118 | var deltaDis = this._moveSpeedLen*delta;
119 | if(dis < deltaDis || (this.destroyWhenOutofStage && !cc.rectContainsRect(flax.stageRect, flax.getRect(this, true)))){
120 | this._moveOver();
121 | this.stopMove();
122 | }else{
123 | var rect = flax.getRect(this, this.parent);
124 | //when collide with the bounder, bounce back
125 | if(this.restrainRect){
126 | var dx = 0;
127 | var dy = 0;
128 | if(rect.x < this.restrainRect.x){
129 | dx = 1.0;
130 | }else if(rect.x > this.restrainRect.x + this.restrainRect.width - rect.width) {
131 | dx = -1.0;
132 | }
133 | if(rect.y < this.restrainRect.y){
134 | dy = 1.0;
135 | }else if(rect.y > this.restrainRect.y + this.restrainRect.height - rect.height) {
136 | dy = -1.0;
137 | }
138 | if(this.inRandom){
139 | if(dx) this.moveSpeed.x = dx*Math.abs(this.moveSpeed.x);
140 | if(dy) this.moveSpeed.y = dy*Math.abs(this.moveSpeed.y);
141 | }else if(dx || dy){
142 | //todo
143 | // this.moveSpeed = cc.p();
144 | // this.stopMove();
145 | }
146 | }
147 | var acc = this.moveAcc;
148 | if(this.gravityOnMove) acc = cc.pAdd(acc || cc.p(), this.gravityOnMove);
149 | if(acc) {
150 | this.moveSpeed = cc.pAdd(this.moveSpeed, cc.pMult(acc, delta));
151 | }
152 | this.setPosition(cc.pAdd(pos, cc.pMult(this.moveSpeed, delta)));
153 | }
154 | },
155 | _moveOver:function()
156 | {
157 | if(this._targetPos) this.setPosition(this._targetPos);
158 | if(this._callBack){
159 | this._callBack.apply(this._callContext || this);
160 | this._callBack = null;
161 | }
162 | if(this.destroyWhenReach){
163 | this.destroy();
164 | }
165 | }
166 | }
--------------------------------------------------------------------------------
/src/flax/module/PhysicsModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-9-17.
3 | */
4 |
5 | flax.PhysicsModule = {
6 | _physicsBody:null,
7 | _physicsToBeSet:null,
8 | _physicsBodyParam:null,
9 | _physicsColliders:null,
10 | onEnter:function()
11 | {
12 | if(this._physicsColliders == null) this._physicsColliders = [];
13 | if(this._physicsBodyParam) {
14 | this.createPhysics(this._physicsBodyParam.type, this._physicsBodyParam.fixedRotation, this._physicsBodyParam.bullet);
15 | }
16 | if(this._physicsToBeSet){
17 | for(var name in this._physicsToBeSet){
18 | var collider = this.getCollider(name);
19 | var param = this._physicsToBeSet[name];
20 | collider.createPhysics(param.density, param.friction, param.restitution, param.isSensor, param.catBits, param.maskBits);
21 | delete this._physicsToBeSet[name];
22 | if(this._physicsColliders.indexOf(collider) == -1) this._physicsColliders.push(collider);
23 | }
24 | }
25 | },
26 | onExit:function()
27 | {
28 | //remove physics
29 | for(var i = 0; i < this._physicsColliders.length; i++){
30 | this._physicsColliders[i].destroyPhysics();
31 | }
32 | this._physicsColliders = [];
33 |
34 | if(this._physicsBody){
35 | flax.removePhysicsBody(this._physicsBody);
36 | this._physicsBody = null;
37 | }
38 | this._physicsBodyParam = null;
39 | },
40 | getPhysicsBody:function(){
41 | return this._physicsBody;
42 | },
43 | createPhysics:function(type, fixedRotation, bullet){
44 | if(type == null) type = Box2D.Dynamics.b2Body.b2_dynamicBody;
45 | this._physicsBodyParam = {type:type, fixedRotation:fixedRotation, bullet:bullet};
46 | if(!this.parent) return null;
47 | if(this._physicsBody == null) {
48 | var def = new Box2D.Dynamics.b2BodyDef();
49 | def.type = type;
50 | def.fixedRotation = fixedRotation;
51 | def.bullet = bullet;
52 | def.userData = this;
53 | var pos = flax.getPosition(this, true);
54 | def.position.Set(pos.x / PTM_RATIO, pos.y / PTM_RATIO);
55 | this._physicsBody = flax.getPhysicsWorld().CreateBody(def);
56 | this._physicsBody.__rotationOffset = this.rotation;
57 | }
58 | return this._physicsBody;
59 | },
60 | destroyPhysics:function(){
61 | this.removePhysicsShape();
62 | },
63 | addPhysicsShape:function(name, density, friction,restitution, isSensor, catBits, maskBits){
64 | if(this._physicsBody == null) throw "Please createPhysics firstly!";
65 | var collider = this.getCollider(name);
66 | if(collider == null) {
67 | cc.log("There is no collider named: "+name);
68 | return null;
69 | }else if(collider.physicsFixture){
70 | return collider.physicsFixture;
71 | }
72 | var param = {density:density,friction:friction,restitution:restitution,isSensor:isSensor,catBits:catBits,maskBits:maskBits};
73 | if(this.parent) {
74 | collider.setOwner(this);
75 | var fixture = collider.createPhysics(density, friction, restitution, isSensor, catBits, maskBits);
76 | if(this._physicsColliders.indexOf(collider) == -1) this._physicsColliders.push(collider);
77 | return fixture;
78 | }
79 | if(this._physicsToBeSet == null) this._physicsToBeSet = {};
80 | if(this._physicsToBeSet[name] == null) this._physicsToBeSet[name] = param;
81 | return null;
82 | },
83 | /**
84 | * Remove the physics of name, if not set name, remove all
85 | * */
86 | removePhysicsShape:function(name){
87 | var i = this._physicsColliders.length;
88 | while(i--){
89 | var c = this._physicsColliders[i];
90 | if(name == null || c.name == name){
91 | c.destroyPhysics();
92 | this._physicsColliders.splice(i, 1);
93 | }
94 | }
95 | if(this._physicsColliders.length == 0){
96 | flax.removePhysicsBody(this._physicsBody);
97 | this._physicsBody = null;
98 | }
99 | }
100 | }
--------------------------------------------------------------------------------
/src/flax/module/ScreenLayoutModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-5-10.
3 | */
4 | var HLayoutType = {
5 | LEFT:0,
6 | CENTER:1,
7 | RIGHT:2
8 | }
9 | var VLayoutType = {
10 | BOTTOM:0,
11 | MIDDLE:1,
12 | TOP:2
13 | }
14 |
15 | flax.getLayoutPosition = function(target, hLayout, vLayout)
16 | {
17 | var rect = flax.getRect(target, true);
18 | var sCenter = cc.visibleRect.center;
19 | var anchorPos = target.getAnchorPointInPoints();
20 |
21 | var x = 0;
22 | var y = 0;
23 |
24 | switch(hLayout){
25 | case HLayoutType.LEFT:
26 | x = 0;
27 | break;
28 | case HLayoutType.CENTER:
29 | x = sCenter.x - rect.width/2;
30 | break;
31 | case HLayoutType.RIGHT:
32 | x = cc.visibleRect.right.x - rect.width;
33 | break;
34 | }
35 | switch(vLayout){
36 | case VLayoutType.BOTTOM:
37 | y = 0;
38 | break;
39 | case VLayoutType.MIDDLE:
40 | y = sCenter.y - rect.height/2;
41 | break;
42 | case VLayoutType.TOP:
43 | y = cc.visibleRect.top.y - rect.height;
44 | break;
45 | }
46 |
47 | var scale = flax.getScale(target, true);
48 | var offsetX = !hLayout ? cc.visibleRect.bottomLeft.x : 0;
49 | var offsetY = !vLayout ? cc.visibleRect.bottomLeft.y : 0;
50 | var pos = cc.p(x + offsetX + anchorPos.x*scale.x, y + offsetY + anchorPos.y*scale.y);
51 |
52 | if(target.parent){
53 | pos = target.parent.convertToNodeSpace(pos);
54 | }
55 | return pos;
56 | }
57 |
58 | flax.ScreenLayoutModule = {
59 | _isAutoLayout:false,
60 | _hlayout:null,
61 | _vlayout:null,
62 | _offsetX:0,
63 | _offsetY:0,
64 | onEnter:function()
65 | {
66 | flax.onDeviceRotate.add(this._updateLayout, this);
67 | flax.onScreenResize.add(this._updateLayout, this);
68 | },
69 | onExit:function()
70 | {
71 | flax.onDeviceRotate.remove(this._updateLayout, this);
72 | flax.onScreenResize.remove(this._updateLayout, this);
73 | },
74 | setLayoutOffset:function(offsetX, offsetY)
75 | {
76 | this._offsetX = offsetX;
77 | this._offsetY = offsetY;
78 | this._updateLayout();
79 | },
80 | /**
81 | * Set the layout
82 | * @param {HLayoutType} hLayout Layout type on horizontal direction
83 | * @param {VLayoutType} vLayout Layout type on vertical direction
84 | * */
85 | setLayout:function(hLayout, vLayout)
86 | {
87 | this._isAutoLayout = false;
88 | this._hlayout = hLayout;
89 | this._vlayout = vLayout;
90 | var pos = flax.getLayoutPosition(this, hLayout, vLayout);
91 | pos.x += this._offsetX;
92 | pos.y += this._offsetY;
93 | this.setPosition(pos);
94 | },
95 | /**
96 | * Auto layout on the screen according on the designed position.
97 | * In most situations, the object on the top-left will still on the top-left when screen size changed.
98 | * Note: This can be used only on the resolution policy of cc.ResolutionPolicy.NO_BORDER
99 | * */
100 | autoLayout:function()
101 | {
102 | if(cc.view.getResolutionPolicy() != cc.ResolutionPolicy.NO_BORDER) return;
103 |
104 | this._isAutoLayout = true;
105 |
106 | var rect = flax.getRect(this, this.parent);
107 | var sCenter = cc.visibleRect.center;
108 | var anchorPos = this.getAnchorPointInPoints();
109 | var offsetPlus = 0;
110 |
111 | var rateX = cc.visibleRect.width/flax.designedStageSize.width;
112 | if(rateX != 1.0){
113 | var offsetX = this.x - sCenter.x;
114 | if(offsetX > 0) {
115 | offsetPlus = rect.width;
116 | }
117 | offsetX = rect.x + offsetPlus - sCenter.x;
118 | this.x = sCenter.x + offsetX*rateX + anchorPos.x*this.scaleX - offsetPlus + this._offsetX;
119 | }
120 |
121 | var rateY = cc.visibleRect.height/flax.designedStageSize.height;
122 | if(rateY != 1.0){
123 | var offsetY = this.y - sCenter.y;
124 | offsetPlus = 0;
125 | if(offsetY > 0) {
126 | offsetPlus = rect.height;
127 | }
128 | offsetY = rect.y + offsetPlus - sCenter.y;
129 | this.y = sCenter.y + offsetY*rateY + anchorPos.y*this.scaleY - offsetPlus + this._offsetY;
130 | }
131 | },
132 | _updateLayout:function(landscape)
133 | {
134 | if(this._isAutoLayout){
135 | this.autoLayout();
136 | }else if(this._hlayout != null && this._vlayout != null){
137 | this.setLayout(this._hlayout, this._vlayout);
138 | }
139 | }
140 | }
--------------------------------------------------------------------------------
/src/flax/module/TileMapModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by long on 15-3-21.
3 | */
4 | flax.TileMapModule = {
5 | tx:0,
6 | ty:0,
7 | autoUpdateTileWhenMove:true,
8 | tileValue:TileValue.WALKABLE,
9 | _tileMap:null,
10 | _tileInited:false,
11 |
12 | onEnter:function()
13 | {
14 | if(this._tileMap && !this._tileInited) {
15 | this.updateTile(true);
16 | }
17 | },
18 | onExit:function()
19 | {
20 | if(this._tileMap) this._tileMap.removeObject(this);
21 | this._tileMap = null;
22 | this._tileInited = false;
23 | },
24 | onPosition:function()
25 | {
26 | if(this.autoUpdateTileWhenMove && this._tileMap){
27 | this.updateTile();
28 | }
29 | },
30 | getTileMap:function()
31 | {
32 | return this._tileMap;
33 | },
34 | setTileMap:function(map)
35 | {
36 | if(map && !(map instanceof flax.TileMap)) map = flax.getTileMap(map);
37 | if(this._tileMap == map) return;
38 | if(this._tileMap) this._tileMap.removeObject(this);
39 | this._tileMap = map;
40 | if(this._tileMap == null) return;
41 |
42 | if(this.parent) {
43 | this.updateTile(true);
44 | //todo
45 | // this._updateCollider();
46 | }
47 | },
48 | updateTile:function(forceUpdate){
49 | if(!this._tileMap) return;
50 | var pos = this.getPosition();
51 | if(this.parent) pos = this.parent.convertToWorldSpace(pos);
52 | var t = this._tileMap.getTileIndex(pos);
53 | this.setTile(t.x, t.y, forceUpdate);
54 | },
55 | setTile:function(tx, ty, forceUpdate)
56 | {
57 | if (forceUpdate === true || tx != this.tx || ty != this.ty) {
58 | var oldTx = this.tx;
59 | var oldTy = this.ty;
60 | this.tx = tx;
61 | this.ty = ty;
62 | if(this._tileMap && this.parent)
63 | {
64 | this._tileMap.removeObject(this, oldTx, oldTy);
65 | if(this.parent) {
66 | this._tileMap.addObject(this);
67 | this._tileInited = true;
68 | }
69 | }
70 | }else {
71 | //update the zOrder sort in the tile
72 | // this._tileMap.updateLayout(tx, ty);
73 | }
74 | },
75 | snapToTile:function(tx, ty, autoAdd)
76 | {
77 | this._tileMap.snapToTile(this,tx, ty, autoAdd);
78 | }
79 | };
--------------------------------------------------------------------------------
/src/flax/signal/SignalBinding.js:
--------------------------------------------------------------------------------
1 | // SignalBinding -------------------------------------------------
2 | //================================================================
3 |
4 | /**
5 | * Object that represents a binding between a Signal and a listener function.
6 | *
- This is an internal constructor and shouldn't be called by regular users.
7 | *
- inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.
8 | * @author Miller Medeiros
9 | * @constructor
10 | * @internal
11 | * @name SignalBinding
12 | * @param {Signal} signal Reference to Signal object that listener is currently bound to.
13 | * @param {Function} listener Handler function bound to the signal.
14 | * @param {boolean} isOnce If binding should be executed just once.
15 | * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
16 | * @param {Number} [priority] The priority level of the event listener. (default = 0).
17 | */
18 | function SignalBinding(signal, listener, isOnce, listenerContext, priority) {
19 |
20 | /**
21 | * Handler function bound to the signal.
22 | * @type Function
23 | * @private
24 | */
25 | this._listener = listener;
26 |
27 | /**
28 | * If binding should be executed just once.
29 | * @type boolean
30 | * @private
31 | */
32 | this._isOnce = isOnce;
33 |
34 | /**
35 | * Context on which listener will be executed (object that should represent the `this` variable inside listener function).
36 | * @memberOf SignalBinding.prototype
37 | * @name context
38 | * @type Object|undefined|null
39 | */
40 | this.context = listenerContext;
41 |
42 | /**
43 | * Reference to Signal object that listener is currently bound to.
44 | * @type Signal
45 | * @private
46 | */
47 | this._signal = signal;
48 |
49 | /**
50 | * Listener priority
51 | * @type Number
52 | * @private
53 | */
54 | this._priority = priority || 0;
55 | }
56 |
57 | SignalBinding.prototype = {
58 |
59 | /**
60 | * If binding is active and should be executed.
61 | * @type boolean
62 | */
63 | actived : true,
64 |
65 | /**
66 | * Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute`. (curried parameters)
67 | * @type Array|null
68 | */
69 | params : null,
70 |
71 | /**
72 | * Call listener passing arbitrary parameters.
73 | * If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.
74 | * @param {Array} [paramsArr] Array of parameters that should be passed to the listener
75 | * @return {*} Value returned by the listener.
76 | */
77 | execute : function (paramsArr) {
78 | var handlerReturn, params;
79 | if (this.actived && !!this._listener) {
80 | params = this.params? this.params.concat(paramsArr) : paramsArr;
81 | handlerReturn = this._listener.apply(this.context, params);
82 | if (this._isOnce) {
83 | this.detach();
84 | }
85 | }
86 | return handlerReturn;
87 | },
88 |
89 | /**
90 | * Detach binding from signal.
91 | * - alias to: mySignal.remove(myBinding.getListener());
92 | * @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached.
93 | */
94 | detach : function () {
95 | return this.isBound()? this._signal.remove(this._listener, this.context) : null;
96 | },
97 |
98 | /**
99 | * @return {Boolean} `true` if binding is still bound to the signal and have a listener.
100 | */
101 | isBound : function () {
102 | return (!!this._signal && !!this._listener);
103 | },
104 |
105 | /**
106 | * @return {boolean} If SignalBinding will only be executed once.
107 | */
108 | isOnce : function () {
109 | return this._isOnce;
110 | },
111 |
112 | /**
113 | * @return {Function} Handler function bound to the signal.
114 | */
115 | getListener : function () {
116 | return this._listener;
117 | },
118 |
119 | /**
120 | * @return {Signal} Signal that listener is currently bound to.
121 | */
122 | getSignal : function () {
123 | return this._signal;
124 | },
125 |
126 | /**
127 | * Delete instance properties
128 | * @private
129 | */
130 | _destroy : function () {
131 | delete this._signal;
132 | delete this._listener;
133 | delete this.context;
134 | },
135 |
136 | /**
137 | * @return {string} String representation of the object.
138 | */
139 | toString : function () {
140 | return '[SignalBinding isOnce:' + this._isOnce +', isBound:'+ this.isBound() +', actived:' + this.actived + ']';
141 | }
142 |
143 | };
144 |
--------------------------------------------------------------------------------
/src/flax/signal/wrapper.js:
--------------------------------------------------------------------------------
1 | /*jslint onevar:true, undef:true, newcap:true, regexp:true, bitwise:true, maxerr:50, indent:4, white:false, nomen:false, plusplus:false */
2 | /*global define:false, require:false, exports:false, module:false, signals:false */
3 |
4 | //::LICENSE:://
5 | (function(global){
6 |
7 | //::SIGNAL_BINDING_JS:://
8 |
9 | //::SIGNAL_JS:://
10 |
11 | //exports to multiple environments
12 | if(typeof define === 'function' && define.amd){ //AMD
13 | define(function () { return signals; });
14 | } else if (typeof module !== 'undefined' && module.exports){ //node
15 | module.exports = signals;
16 | } else { //browser
17 | //use string because of Google closure compiler ADVANCED_MODE
18 | /*jslint sub:true */
19 | global['signals'] = signals;
20 | }
21 |
22 | }(this));
23 |
--------------------------------------------------------------------------------
/src/resource.js:
--------------------------------------------------------------------------------
1 | var music = {
2 | chop:"res/music/chop.mp3",
3 | fail:"res/music/scream.wav",
4 | bg:"res/music/bg.mp3",
5 | gun0:"res/music/gun0.mp3",
6 | gun1:"res/music/gun1.mp3"
7 | }
8 |
9 | var res = {
10 | sceneNav:"res/sceneNav.plist",
11 | sceneNav_png:"res/sceneNav.png",
12 |
13 | animation:"res/monkeyRun.plist",
14 | animation_png:"res/monkeyRun.png",
15 |
16 | skeleton:"res/skeletonControl.plist",
17 | skeleton_png:"res/skeletonControl.png",
18 |
19 | customClick:"res/customClick.plist",
20 | customClick_png:"res/customClick.png",
21 |
22 | uiButton:"res/uiButton.plist",
23 | uiButton_png:"res/uiButton.png",
24 |
25 | uiProgress:"res/uiProgress.plist",
26 | uiProgress_png:"res/uiProgress.png",
27 |
28 | uiBMFont:"res/uiBmFont.plist",
29 | uiBMFont_png:"res/uiBmFont.png",
30 |
31 | uiInput:"res/uiInput.plist",
32 | uiInput_png:"res/uiInput.png",
33 |
34 | uiPanel:"res/uiPanel.plist",
35 | uiPanel_png:"res/uiPanel.png",
36 |
37 | effect:"res/effect.plist",
38 | effect_png:"res/effect.png",
39 |
40 | scrollingBG:"res/scrollingBG.plist",
41 | scrollingBG_png:"res/scrollingBG.png",
42 |
43 | tiledImage:"res/tiledImage.plist",
44 | tiledImage_png:"res/tiledImage.png",
45 |
46 | poppingStars:"res/gamePopStars.plist",
47 | poppingStars_png:"res/gamePopStars.png",
48 |
49 | bubbles:"res/gameBubbles.plist",
50 | bubbles_png:"res/gameBubbles.png",
51 |
52 | fruits:"res/gameFruitsLink.plist",
53 | fruits_png:"res/gameFruitsLink.png",
54 |
55 | shooters:"res/gameShooters.plist",
56 | shooters_png:"res/gameShooters.png",
57 |
58 | physics:"res/gamePhysics.plist",
59 | physics_png:"res/gamePhysics.png",
60 |
61 | timberQiang:"res/gameTimberQiang.plist",
62 | timberQiang_png:"res/gameTimberQiang.png"
63 | };
64 |
65 | var res_animation = [
66 | res.sceneNav,
67 | res.sceneNav_png,
68 | res.animation,
69 | res.animation_png
70 | ]
71 |
72 | var res_skeleton = [
73 | res.sceneNav,
74 | res.sceneNav_png,
75 | res.animation,
76 | res.animation_png,
77 | res.skeleton,
78 | res.skeleton_png
79 | ]
80 | var res_customClick = [
81 | res.sceneNav,
82 | res.sceneNav_png,
83 | res.customClick,
84 | res.customClick_png
85 | ]
86 | var res_button = [
87 | res.sceneNav,
88 | res.sceneNav_png,
89 | res.uiButton,
90 | res.uiButton_png
91 | ]
92 |
93 | var res_progress = [
94 | res.sceneNav,
95 | res.sceneNav_png,
96 | res.animation,
97 | res.animation_png,
98 | res.uiProgress,
99 | res.uiProgress_png
100 | ]
101 |
102 | var res_uiBmFont = [
103 | res.sceneNav,
104 | res.sceneNav_png,
105 | res.uiPanel,
106 | res.uiPanel_png,
107 | res.uiBMFont,
108 | res.uiBMFont_png
109 | ]
110 |
111 | var res_uiInput = [
112 | res.sceneNav,
113 | res.sceneNav_png,
114 | res.uiPanel,
115 | res.uiPanel_png,
116 | res.uiInput,
117 | res.uiInput_png
118 | ]
119 |
120 | var res_uiPanel = [
121 | res.sceneNav,
122 | res.sceneNav_png,
123 | res.uiPanel,
124 | res.uiPanel_png
125 | ]
126 |
127 | var res_effect = [
128 | res.sceneNav,
129 | res.sceneNav_png,
130 | res.effect,
131 | res.effect_png
132 | ]
133 |
134 | var res_scrollingBG = [
135 | res.sceneNav,
136 | res.sceneNav_png,
137 | res.scrollingBG,
138 | res.scrollingBG_png
139 | ]
140 |
141 | var res_tiledImage = [
142 | res.sceneNav,
143 | res.sceneNav_png,
144 | res.tiledImage,
145 | res.tiledImage_png
146 | ]
147 |
148 | var res_poppingStars = [
149 | res.sceneNav,
150 | res.sceneNav_png,
151 | res.poppingStars,
152 | res.poppingStars_png
153 | ]
154 |
155 | var res_bubbles = [
156 | res.sceneNav,
157 | res.sceneNav_png,
158 | res.bubbles,
159 | res.bubbles_png
160 | ]
161 |
162 | var res_fruitsLink = [
163 | res.sceneNav,
164 | res.sceneNav_png,
165 | res.fruits,
166 | res.fruits_png
167 | ]
168 |
169 | var res_shooters = [
170 | res.sceneNav,
171 | res.sceneNav_png,
172 | res.scrollingBG,
173 | res.scrollingBG_png,
174 | res.shooters,
175 | res.shooters_png,
176 | music.gun0,
177 | music.gun1
178 | ]
179 |
180 | var res_physics = [
181 | res.sceneNav,
182 | res.sceneNav_png,
183 | res.physics,
184 | res.physics_png
185 | ]
186 |
187 | var res_timberQiang = [
188 | res.sceneNav,
189 | res.sceneNav_png,
190 | music.chop,
191 | music.fail,
192 | music.bg,
193 | res.timberQiang,
194 | res.timberQiang_png
195 | ];
196 |
--------------------------------------------------------------------------------