├── .gitignore
├── src
├── music
│ ├── win.mp3
│ ├── boom.mp3
│ ├── cake.mp3
│ ├── clock.mp3
│ ├── jump.mp3
│ ├── life.mp3
│ ├── lose.mp3
│ ├── basket.mp3
│ ├── gamebg.mp3
│ └── lessboom.mp3
├── image
│ ├── icons.png
│ ├── background.jpg
│ ├── explosion.png
│ ├── rabbit-big.png
│ ├── rabbit-win.png
│ ├── rabbit-lose.png
│ ├── rabbit-small.png
│ └── explosion.plist
├── cocos2d
│ ├── .DS_Store
│ ├── core
│ │ ├── cocos2d_externs.js
│ │ ├── scenes
│ │ │ ├── CCScene.js
│ │ │ └── CCLoaderScene.js
│ │ ├── support
│ │ │ └── TransformUtils.js
│ │ ├── sprites
│ │ │ ├── SpritesPropertyDefine.js
│ │ │ ├── CCBakeSprite.js
│ │ │ └── CCSpriteBatchNodeCanvasRenderCmd.js
│ │ ├── labelttf
│ │ │ ├── LabelTTFPropertyDefine.js
│ │ │ └── CCLabelTTFWebGLRenderCmd.js
│ │ ├── platform
│ │ │ ├── CCVisibleRect.js
│ │ │ ├── CCInputExtension.js
│ │ │ ├── CCTypesPropertyDefine.js
│ │ │ ├── CCLoaders.js
│ │ │ ├── CCSAXParser.js
│ │ │ └── CCScreen.js
│ │ ├── event-manager
│ │ │ ├── CCEventExtension.js
│ │ │ └── CCTouch.js
│ │ ├── base-nodes
│ │ │ └── BaseNodesPropertyDefine.js
│ │ └── renderer
│ │ │ └── RendererWebGL.js
│ ├── particle
│ │ ├── CCParticleBatchNodeCanvasRenderCmd.js
│ │ └── CCParticleBatchNodeWebGLRenderCmd.js
│ ├── shape-nodes
│ │ └── CCDrawNodeWebGLRenderCmd.js
│ ├── kazmath
│ │ ├── utility.js
│ │ ├── aabb.js
│ │ ├── gl
│ │ │ └── mat4stack.js
│ │ ├── vec2.js
│ │ ├── plane.js
│ │ ├── vec4.js
│ │ └── ray2.js
│ ├── compression
│ │ ├── ZipUtils.js
│ │ └── base64.js
│ ├── physics
│ │ ├── CCPhysicsDebugNodeWebGLRenderCmd.js
│ │ ├── CCPhysicsDebugNodeCanvasRenderCmd.js
│ │ ├── CCPhysicsSpriteCanvasRenderCmd.js
│ │ └── CCPhysicsSpriteWebGLRenderCmd.js
│ ├── parallax
│ │ └── CCParallaxNodeRenderCmd.js
│ ├── tilemap
│ │ ├── CCTMXLayerWebGLRenderCmd.js
│ │ └── CCTMXObjectGroup.js
│ ├── motion-streak
│ │ └── CCMotionStreakWebGLRenderCmd.js
│ ├── labels
│ │ ├── CCLabelBMFontWebGLRenderCmd.js
│ │ └── CCLabelAtlasCanvasRenderCmd.js
│ ├── node-grid
│ │ ├── CCNodeGridWebGLRenderCmd.js
│ │ └── CCNodeGrid.js
│ ├── effects
│ │ └── CCGrabber.js
│ ├── render-texture
│ │ └── CCRenderTextureCanvasRenderCmd.js
│ ├── actions3d
│ │ └── CCActionPageTurn3D.js
│ └── transitions
│ │ └── CCTransitionPageTurn.js
├── project.json
├── js
│ ├── main.js
│ ├── gamePlay
│ │ ├── layer
│ │ │ └── backgroundLayer.js
│ │ ├── sprite
│ │ │ ├── timeSprite.js
│ │ │ ├── lifeSprite.js
│ │ │ ├── scoreSprite.js
│ │ │ ├── rabbitWinSprite.js
│ │ │ ├── rabbitLoseSprite.js
│ │ │ ├── explosionSprite.js
│ │ │ ├── propSprite.js
│ │ │ ├── plusSprite.js
│ │ │ ├── moonCakeSprite.js
│ │ │ └── rabbitSprite.js
│ │ └── scene
│ │ │ └── gamePlay.js
│ └── connfig
│ │ ├── resource.js
│ │ └── config.js
└── index.html
├── package.json
├── README.md
├── LICENSE
└── gulpfile.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | npm-debug.log
3 | .idea/
4 | .DS_Store
5 | res/
6 | dest/
7 |
--------------------------------------------------------------------------------
/src/music/win.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/music/win.mp3
--------------------------------------------------------------------------------
/src/image/icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/image/icons.png
--------------------------------------------------------------------------------
/src/music/boom.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/music/boom.mp3
--------------------------------------------------------------------------------
/src/music/cake.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/music/cake.mp3
--------------------------------------------------------------------------------
/src/music/clock.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/music/clock.mp3
--------------------------------------------------------------------------------
/src/music/jump.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/music/jump.mp3
--------------------------------------------------------------------------------
/src/music/life.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/music/life.mp3
--------------------------------------------------------------------------------
/src/music/lose.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/music/lose.mp3
--------------------------------------------------------------------------------
/src/cocos2d/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/cocos2d/.DS_Store
--------------------------------------------------------------------------------
/src/music/basket.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/music/basket.mp3
--------------------------------------------------------------------------------
/src/music/gamebg.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/music/gamebg.mp3
--------------------------------------------------------------------------------
/src/music/lessboom.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/music/lessboom.mp3
--------------------------------------------------------------------------------
/src/image/background.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/image/background.jpg
--------------------------------------------------------------------------------
/src/image/explosion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/image/explosion.png
--------------------------------------------------------------------------------
/src/image/rabbit-big.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/image/rabbit-big.png
--------------------------------------------------------------------------------
/src/image/rabbit-win.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/image/rabbit-win.png
--------------------------------------------------------------------------------
/src/image/rabbit-lose.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/image/rabbit-lose.png
--------------------------------------------------------------------------------
/src/image/rabbit-small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ustbhuangyi/FunnyRabbit/HEAD/src/image/rabbit-small.png
--------------------------------------------------------------------------------
/src/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "showFPS": false,
3 | "debugMode": 0,
4 | "frameRate": 60,
5 | "id": "gameCanvas",
6 | "renderMode": 0,
7 | "jsList": []
8 | }
9 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "engines": {
4 | "node": ">=0.10.0"
5 | },
6 | "devDependencies": {
7 | "browser-sync": "^2.2.1",
8 | "gulp": "^3.6.0",
9 | "gulp-concat": "^2.4.2",
10 | "del": "^0.1.0"
11 | }
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/src/js/main.js:
--------------------------------------------------------------------------------
1 | cc.game.onStart = function(){
2 |
3 | //load resources
4 | cc.LoaderScene.preload(g_resources, function () {
5 | //cc.director.setProjection(cc.Director.PROJECTION_2D);
6 | cc.director.runScene(new GamePlayScene());
7 | }, this);
8 | };
9 | cc.game.run();
10 |
--------------------------------------------------------------------------------
/src/js/gamePlay/layer/backgroundLayer.js:
--------------------------------------------------------------------------------
1 | var GPBackgroundLayer = cc.LayerColor.extend({
2 |
3 | ctor: function (color) {
4 |
5 | this._super(color);
6 |
7 | this.initBackground();
8 |
9 | },
10 |
11 | initBackground: function () {
12 | var sptBg = new cc.Sprite(res.background);
13 | sptBg.attr({
14 | x: GC.w_2,
15 | y: GC.h_2
16 | });
17 | this.addChild(sptBg);
18 | }
19 | });
20 |
--------------------------------------------------------------------------------
/src/js/gamePlay/sprite/timeSprite.js:
--------------------------------------------------------------------------------
1 | var TimeSprite = cc.Sprite.extend({
2 |
3 | ctor: function (value) {
4 | this._super();
5 | this.value = value;
6 | var frame = this.getTimeFrame();
7 | this.setSpriteFrame(frame);
8 | },
9 | getTimeFrame: function () {
10 | var frameName = 't-' + this.value + '.png';
11 | var frame = cc.spriteFrameCache.getSpriteFrame(frameName);
12 | return frame;
13 | },
14 | update: function (value) {
15 | this.value = value;
16 | var frame = this.getTimeFrame();
17 | this.setSpriteFrame(frame);
18 | }
19 | });
20 |
--------------------------------------------------------------------------------
/src/js/gamePlay/sprite/lifeSprite.js:
--------------------------------------------------------------------------------
1 | var LifeSprite = cc.Sprite.extend({
2 |
3 | ctor: function (value) {
4 | this._super();
5 | this.value = value;
6 | var frame = this.getLifeFrame();
7 | this.setSpriteFrame(frame);
8 | },
9 | getLifeFrame: function () {
10 | var frameName = 'life-' + this.value + '.png';
11 | var frame = cc.spriteFrameCache.getSpriteFrame(frameName);
12 | return frame;
13 | },
14 | update: function (value) {
15 | this.value = value;
16 | var frame = this.getLifeFrame();
17 | this.setSpriteFrame(frame);
18 | }
19 | });
20 |
--------------------------------------------------------------------------------
/src/js/gamePlay/sprite/scoreSprite.js:
--------------------------------------------------------------------------------
1 | var ScoreSprite = cc.Sprite.extend({
2 |
3 | ctor: function (value) {
4 | this._super();
5 | this.value = value;
6 | var frame = this.getScoreFrame();
7 | this.setSpriteFrame(frame);
8 | },
9 | getScoreFrame: function () {
10 | var frameName = 's-' + this.value + '.png';
11 | var frame = cc.spriteFrameCache.getSpriteFrame(frameName);
12 | return frame;
13 | },
14 | update: function (value) {
15 | this.value = value;
16 | var frame = this.getScoreFrame();
17 | this.setSpriteFrame(frame);
18 | }
19 | });
20 |
--------------------------------------------------------------------------------
/src/js/gamePlay/sprite/rabbitWinSprite.js:
--------------------------------------------------------------------------------
1 | var RabbitWinSprite = cc.Sprite.extend({
2 |
3 | ctor: function () {
4 | var frame = cc.spriteFrameCache.getSpriteFrame('rabbit-win-1.png');
5 | this._super(frame);
6 | },
7 | play: function () {
8 | var animFrames = [];
9 | var str = '';
10 | var frame;
11 | for (var i = 1; i < 20; i++) {
12 | str = 'rabbit-win-' + i + '.png';
13 | frame = cc.spriteFrameCache.getSpriteFrame(str);
14 | animFrames.push(frame);
15 | }
16 | var animation = new cc.Animation(animFrames, 0.2);
17 |
18 | this.runAction(cc.sequence(
19 | cc.animate(animation)
20 | ));
21 |
22 | if (GC.musicOn) {
23 | cc.audioEngine.playEffect(res.win_music);
24 | }
25 | }
26 | });
27 |
--------------------------------------------------------------------------------
/src/js/gamePlay/sprite/rabbitLoseSprite.js:
--------------------------------------------------------------------------------
1 | var RabbitLoseSprite = cc.Sprite.extend({
2 |
3 | ctor: function () {
4 | var frame = cc.spriteFrameCache.getSpriteFrame('rabbit-lose-1.png');
5 | this._super(frame);
6 | },
7 | play: function () {
8 | var animFrames = [];
9 | var str = '';
10 | var frame;
11 | for (var i = 1; i < 14; i++) {
12 | str = 'rabbit-lose-' + i + '.png';
13 | frame = cc.spriteFrameCache.getSpriteFrame(str);
14 | animFrames.push(frame);
15 | }
16 | var animation = new cc.Animation(animFrames, 0.2);
17 |
18 | this.runAction(cc.sequence(
19 | cc.animate(animation)
20 | ));
21 |
22 | if (GC.musicOn) {
23 | cc.audioEngine.playEffect(res.lose_music);
24 | }
25 | }
26 | });
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | FunnyRabbit
2 | ===========
3 |
4 | 新版兔子接月饼的小游戏,很好玩哟~
5 |
6 | [快来体验吧](http://ustbhuangyi.github.io/FunnyRabbit/dist/)
7 |
8 | ## 游戏玩法
9 |
10 | 操作键盘的方向键或者'W'、'A'、'D'键去控制兔子的方向接月饼,月饼的分值不同;
11 | 期间会有道具掉落,吃不同的道具会有不同的效果,注意避开天上掉落的炸弹喔~
12 | 兔子初始2条命,60s倒计时,在规定时间内接的分越多越好:)
13 |
14 | ## 做了哪些优化
15 |
16 | 基于Cocos2djs重构,优化了游戏渲染性能
17 |
18 | 增加了音效、缓动、跳跃等Feature,游戏体验更棒
19 |
20 | ## 如何构建代码
21 |
22 | 签出项目:
23 |
24 | ```bash
25 | git clone git@github.com:ustbhuangyi/FunnyRabbit.git
26 | ```
27 |
28 | 安装依赖
29 |
30 | ```bash
31 | npm install
32 | ```
33 |
34 | 安装gulp
35 |
36 | ```bash
37 | npm -g install gulp
38 | ```
39 |
40 | 编译运行
41 |
42 | ```bash
43 | gulp serve
44 | ```
45 |
46 | ## License
47 | licensed under the [MIT license.](https://github.com/ustbhuangyi/FunnyRabbit/blob/master/LICENSE)
48 |
49 |
50 |
--------------------------------------------------------------------------------
/src/js/gamePlay/sprite/explosionSprite.js:
--------------------------------------------------------------------------------
1 | var ExplosionSprite = cc.Sprite.extend({
2 |
3 | ctor: function () {
4 | var frame = cc.spriteFrameCache.getSpriteFrame('explosion-1.png');
5 | this._super(frame);
6 | },
7 | play: function () {
8 | var animFrames = [];
9 | var str = '';
10 | var frame;
11 | for (var i = 1; i < 5; i++) {
12 | str = 'explosion-' + i + '.png';
13 | frame = cc.spriteFrameCache.getSpriteFrame(str);
14 | animFrames.push(frame);
15 | }
16 | var animation = new cc.Animation(animFrames, 0.2);
17 |
18 | this.runAction(cc.sequence(
19 | cc.animate(animation),
20 | cc.callFunc(this.destroy, this)
21 | ));
22 |
23 | if (GC.musicOn) {
24 | cc.audioEngine.playEffect(res.boom_music);
25 | }
26 | },
27 |
28 | destroy: function () {
29 | g_GPTouchLayer.texExplosionBatch.removeChild(this);
30 | }
31 | });
32 |
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | FunnyRabbit
6 |
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/js/connfig/resource.js:
--------------------------------------------------------------------------------
1 | var res = {
2 | rabbit_small_plist: 'image/rabbit-small.plist',
3 | rabbit_small_png: 'image/rabbit-small.png',
4 | rabbit_big_plist: 'image/rabbit-big.plist',
5 | rabbit_big_png: 'image/rabbit-big.png',
6 | rabbit_win_plist: 'image/rabbit-win.plist',
7 | rabbit_win_png: 'image/rabbit-win.png',
8 | rabbit_lose_plist: 'image/rabbit-lose.plist',
9 | rabbit_lose_png: 'image/rabbit-lose.png',
10 | icons_plist: 'image/icons.plist',
11 | icons_png: 'image/icons.png',
12 | explosion_plist: 'image/explosion.plist',
13 | explosion_png: 'image/explosion.png',
14 | background: 'image/background.jpg',
15 |
16 | bg_music: 'music/gamebg.mp3',
17 | cake_music: 'music/cake.mp3',
18 | boom_music: 'music/boom.mp3',
19 | win_music: 'music/win.mp3',
20 | lose_music: 'music/lose.mp3',
21 | lessboom_music: 'music/lessboom.mp3',
22 | clock_music: 'music/clock.mp3',
23 | life_music: 'music/life.mp3',
24 | basket_music: 'music/basket.mp3',
25 | jump_music: 'music/jump.mp3'
26 | };
27 |
28 | var g_resources = [];
29 | for (var i in res) {
30 | g_resources.push(res[i]);
31 | }
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 HuangYi
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 |
--------------------------------------------------------------------------------
/src/js/gamePlay/sprite/propSprite.js:
--------------------------------------------------------------------------------
1 | var PropSprite = cc.Sprite.extend({
2 |
3 | ctor: function (type) {
4 | this._super();
5 | this.hp = 1;
6 | this.value = GC.valueMap[type];
7 | this.active = true;
8 | this.type = type;
9 | var frame = this.getPropFrame();
10 | this.setSpriteFrame(frame);
11 | },
12 | getPropFrame: function () {
13 | var frameName = this.type + '.png';
14 | var frame = cc.spriteFrameCache.getSpriteFrame(frameName);
15 | return frame;
16 | },
17 |
18 | update: function () {
19 |
20 | var h_2 = this.height / 2 | 0;
21 | //5个像素的buffer
22 | if (this.y <= h_2 + 5) {
23 | this.active = false;
24 | }
25 | if (this.hp <= 0) {
26 | this.destroy();
27 | }
28 | },
29 |
30 | destroy: function () {
31 | this.active = false;
32 | g_GPTouchLayer.texIconsBatch.removeChild(this);
33 | },
34 |
35 | hurt: function () {
36 | if (this.hp > 0) {
37 | this.hp--;
38 | }
39 | },
40 |
41 | collideRect: function (x, y) {
42 | var w = this.width, h = this.height;
43 | return cc.rect(x - w / 2, y - h / 2, w, h);
44 | }
45 | });
46 |
--------------------------------------------------------------------------------
/src/js/gamePlay/scene/gamePlay.js:
--------------------------------------------------------------------------------
1 | var GamePlayScene = cc.Scene.extend({
2 | onEnter:function () {
3 | this._super();
4 |
5 | var layer = new GamePlayLayer();
6 | this.addChild(layer);
7 |
8 | }
9 | });
10 |
11 | var GamePlayLayer = cc.Layer.extend({
12 |
13 | backgroundLayer : null,
14 | touchLayer : null,
15 | ctor : function(){
16 | this._super();
17 |
18 | this.addCache();
19 |
20 | this.addBackgroundLayer();
21 |
22 | this.addTouchLayer();
23 | },
24 |
25 | addCache : function(){
26 |
27 | //将plist添加到缓存
28 | cc.spriteFrameCache.addSpriteFrames(res.rabbit_small_plist);
29 | cc.spriteFrameCache.addSpriteFrames(res.rabbit_big_plist);
30 | cc.spriteFrameCache.addSpriteFrames(res.rabbit_win_plist);
31 | cc.spriteFrameCache.addSpriteFrames(res.rabbit_lose_plist);
32 | cc.spriteFrameCache.addSpriteFrames(res.icons_plist);
33 | cc.spriteFrameCache.addSpriteFrames(res.explosion_plist);
34 | },
35 |
36 |
37 | addBackgroundLayer : function(){
38 |
39 | this.backgroundLayer = new GPBackgroundLayer();
40 | this.addChild(this.backgroundLayer);
41 | },
42 |
43 | addTouchLayer : function(){
44 | this.touchLayer = new GPTouchLayer();
45 | this.addChild(this.touchLayer);
46 | }
47 | });
48 |
--------------------------------------------------------------------------------
/src/js/gamePlay/sprite/plusSprite.js:
--------------------------------------------------------------------------------
1 | var PlusSprite = cc.Sprite.extend({
2 |
3 | ctor: function (value) {
4 | this._super();
5 | this.value = value;
6 | this.active = true;
7 | var frame = this.getPlusFrame();
8 | this.setSpriteFrame(frame);
9 | },
10 | getPlusFrame: function () {
11 | var frameName = 'plus-' + GC.valueMap.indexOf(this.value) + '.png';
12 | var frame = cc.spriteFrameCache.getSpriteFrame(frameName);
13 | return frame;
14 | },
15 |
16 | destroy: function () {
17 | this.visible = false;
18 | this.active = false;
19 | g_GPTouchLayer.texIconsBatch.removeChild(this);
20 | }
21 | });
22 |
23 | PlusSprite.getOrCreatePlus = function (value) {
24 |
25 | var plus;
26 |
27 | for (var i = 0, len = PlusSprite.pluses.length; i < len; i++) {
28 | plus = PlusSprite.pluses[i];
29 | if (plus.active === false && plus.visible === false && plus.value === value) {
30 |
31 | plus.opacity = 255;
32 | plus.visible = true;
33 | plus.active = true;
34 |
35 | return plus;
36 | }
37 | }
38 |
39 | plus = PlusSprite.create(value);
40 |
41 | return plus;
42 | };
43 |
44 | PlusSprite.create = function (value) {
45 |
46 | var plus = new PlusSprite(value);
47 |
48 | PlusSprite.pluses.push(plus);
49 |
50 | return plus;
51 |
52 | };
53 |
--------------------------------------------------------------------------------
/src/cocos2d/core/cocos2d_externs.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @fileoverview Java Script Builtins for windows properties.
3 | *
4 | * @externs
5 | */
6 |
7 | /**
8 | * @see https://cocos2d-x.org
9 | */
10 |
11 | /**
12 | * cocos2d-html5-only.
13 | * @type {string}
14 | */
15 | CSSProperties.prototype._super;
16 |
17 | /**
18 | * cocos2d-html5-only. We need this because the cc.Class.extend's new
19 | * infrastructure requires it.
20 | * @type {string}
21 | */
22 | CSSProperties.prototype.ctor;
23 |
24 | /**
25 | * cocos2d-html5-only.
26 | * @type {string}
27 | */
28 | CSSProperties.prototype.Inflate;
29 |
30 | /**
31 | * cocos2d-html5-only.
32 | * @type {string}
33 | */
34 | CSSProperties.prototype.decompress;
35 |
36 | /**
37 | * Accelerometer api
38 | * cocos2d-html5-only.
39 | * @type {string}
40 | */
41 | CSSProperties.prototype.DeviceOrientationEvent;
42 | CSSProperties.prototype.DeviceMotionEvent;
43 | CSSProperties.prototype.accelerationIncludingGravity;
44 | CSSProperties.prototype.gamma;
45 | CSSProperties.prototype.beta;
46 | CSSProperties.prototype.alpha;
47 |
48 |
49 | var gl = gl || {};
50 | CSSProperties.prototype.gl;
51 |
52 | CSSProperties.prototype.AudioContext;
53 | CSSProperties.prototype.webkitAudioContext;
54 | CSSProperties.prototype.mozAudioContext;
55 | CSSProperties.prototype.createBufferSource;
56 | CSSProperties.prototype.createGain;
57 | CSSProperties.prototype.createGainNode;
58 | CSSProperties.prototype.destination;
59 | CSSProperties.prototype.decodeAudioData;
60 | CSSProperties.prototype.gain;
61 | CSSProperties.prototype.connect;
62 | CSSProperties.prototype.playbackState;
63 | CSSProperties.prototype.noteGrainOn;
64 | CSSProperties.prototype.noteOn;
65 |
66 |
67 |
--------------------------------------------------------------------------------
/src/cocos2d/particle/CCParticleBatchNodeCanvasRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function(){
26 | /**
27 | * cc.ParticleBatchNode's rendering objects of Canvas
28 | */
29 | cc.ParticleBatchNode.CanvasRenderCmd = function(renderable){
30 | cc.Node.CanvasRenderCmd.call(this, renderable);
31 | this._needDraw = false;
32 | };
33 |
34 | var proto = cc.ParticleBatchNode.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
35 | proto.constructor = cc.ParticleBatchNode.CanvasRenderCmd;
36 |
37 | proto._initWithTexture = function(){};
38 | })();
39 |
--------------------------------------------------------------------------------
/src/js/gamePlay/sprite/moonCakeSprite.js:
--------------------------------------------------------------------------------
1 | var MoonCakeSprite = cc.Sprite.extend({
2 |
3 | ctor: function (type) {
4 | this._super();
5 | this.hp = 1;
6 | this.value = GC.valueMap[type];
7 | this.type = type;
8 | this.active = true;
9 | var frame = this.getMoonCakeFrame();
10 | this.setSpriteFrame(frame);
11 | },
12 | getMoonCakeFrame: function () {
13 | var frameName = this.type === GC.CAKE.BOOM ? 'boom.png' : 'cake-' + this.type + '.png';
14 | var frame = cc.spriteFrameCache.getSpriteFrame(frameName);
15 | return frame;
16 | },
17 |
18 | update: function () {
19 |
20 | var h_2 = this.height / 2 | 0;
21 | //5个像素的buffer
22 | if (this.y <= h_2 + 5) {
23 | this.active = false;
24 | }
25 | if (this.hp <= 0) {
26 | this.destroy();
27 | }
28 | },
29 |
30 | destroy: function () {
31 | this.visible = false;
32 | this.active = false;
33 | g_GPTouchLayer.texIconsBatch.removeChild(this);
34 | },
35 |
36 | hurt: function () {
37 | if (this.hp > 0) {
38 | this.hp--;
39 | }
40 | },
41 |
42 | collideRect: function (x, y) {
43 | var w = this.width, h = this.height;
44 | return cc.rect(x - w / 2, y - h / 2, w, h);
45 | }
46 | });
47 |
48 | MoonCakeSprite.getOrCreateMoonCake = function (type) {
49 |
50 | var moonCake;
51 |
52 | for (var i = 0, len = MoonCakeSprite.moonCakes.length; i < len; i++) {
53 | moonCake = MoonCakeSprite.moonCakes[i];
54 | if (moonCake.active === false && moonCake.visible === false && moonCake.type === type) {
55 | moonCake.hp = 1;
56 | moonCake.opacity = 255;
57 | moonCake.visible = true;
58 | moonCake.active = true;
59 |
60 | return moonCake;
61 | }
62 | }
63 |
64 | moonCake = MoonCakeSprite.create(type);
65 |
66 | return moonCake;
67 | };
68 |
69 | MoonCakeSprite.create = function (type) {
70 |
71 | var moonCake = new MoonCakeSprite(type);
72 |
73 | MoonCakeSprite.moonCakes.push(moonCake);
74 |
75 | return moonCake;
76 |
77 | };
78 |
--------------------------------------------------------------------------------
/src/cocos2d/shape-nodes/CCDrawNodeWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function(){
26 | cc.DrawNode.WebGLRenderCmd = function (renderableObject) {
27 | cc.Node.WebGLRenderCmd.call(this, renderableObject);
28 | this._needDraw = true;
29 | };
30 |
31 | cc.DrawNode.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
32 | cc.DrawNode.WebGLRenderCmd.prototype.constructor = cc.DrawNode.WebGLRenderCmd;
33 |
34 | cc.DrawNode.WebGLRenderCmd.prototype.rendering = function (ctx) {
35 | var node = this._node;
36 | cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
37 | this._shaderProgram.use();
38 | this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
39 | node._render();
40 | };
41 | })();
--------------------------------------------------------------------------------
/src/cocos2d/kazmath/utility.js:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2008, Luke Benstead.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification,
9 | are permitted provided that the following conditions are met:
10 |
11 | Redistributions of source code must retain the above copyright notice,
12 | this list of conditions and the following disclaimer.
13 | Redistributions in binary form must reproduce the above copyright notice,
14 | this list of conditions and the following disclaimer in the documentation
15 | and/or other materials provided with the distribution.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 |
30 | /**
31 | * The main namespace of Cocos2d-html5's math library,
32 | * all math core classes, functions, properties and constants are defined in this namespace
33 | * @namespace
34 | * @name cc.math
35 | */
36 | cc.math = cc.math || {};
37 |
38 | //cc.kmPIOver180 = 0.017453; please use cc.RAD
39 |
40 | //cc.kmPIUnder180 = 57.295779; please use cc.DEG
41 |
42 | cc.math.EPSILON = 1.0 / 64.0; //cc.kmEpsilon
43 |
44 | /**
45 | * Returns the square of s (e.g. s*s)
46 | * @param {Number} s
47 | */
48 | cc.math.square = function(s){
49 | return s*s;
50 | };
51 |
52 | cc.math.almostEqual = function(lhs,rhs){
53 | return (lhs + cc.math.EPSILON > rhs && lhs - cc.math.EPSILON < rhs);
54 | };
55 |
--------------------------------------------------------------------------------
/src/cocos2d/compression/ZipUtils.js:
--------------------------------------------------------------------------------
1 | /*--
2 | Copyright 2009-2010 by Stefan Rusterholz.
3 | All rights reserved.
4 | You can choose between MIT and BSD-3-Clause license. License file will be added later.
5 | --*/
6 |
7 | /**
8 | * mixin cc.Codec
9 | */
10 | cc.Codec = {name:'Jacob__Codec'};
11 |
12 | /**
13 | * Unpack a gzipped byte array
14 | * @param {Array} input Byte array
15 | * @returns {String} Unpacked byte string
16 | */
17 | cc.unzip = function () {
18 | return cc.Codec.GZip.gunzip.apply(cc.Codec.GZip, arguments);
19 | };
20 |
21 | /**
22 | * Unpack a gzipped byte string encoded as base64
23 | * @param {String} input Byte string encoded as base64
24 | * @returns {String} Unpacked byte string
25 | */
26 | cc.unzipBase64 = function () {
27 | var tmpInput = cc.Codec.Base64.decode.apply(cc.Codec.Base64, arguments);
28 | return cc.Codec.GZip.gunzip.apply(cc.Codec.GZip, [tmpInput]);
29 | };
30 |
31 | /**
32 | * Unpack a gzipped byte string encoded as base64
33 | * @param {String} input Byte string encoded as base64
34 | * @param {Number} bytes Bytes per array item
35 | * @returns {Array} Unpacked byte array
36 | */
37 | cc.unzipBase64AsArray = function (input, bytes) {
38 | bytes = bytes || 1;
39 |
40 | var dec = this.unzipBase64(input),
41 | ar = [], i, j, len;
42 | for (i = 0, len = dec.length / bytes; i < len; i++) {
43 | ar[i] = 0;
44 | for (j = bytes - 1; j >= 0; --j) {
45 | ar[i] += dec.charCodeAt((i * bytes) + j) << (j * 8);
46 | }
47 | }
48 | return ar;
49 | };
50 |
51 | /**
52 | * Unpack a gzipped byte array
53 | * @param {Array} input Byte array
54 | * @param {Number} bytes Bytes per array item
55 | * @returns {Array} Unpacked byte array
56 | */
57 | cc.unzipAsArray = function (input, bytes) {
58 | bytes = bytes || 1;
59 |
60 | var dec = this.unzip(input),
61 | ar = [], i, j, len;
62 | for (i = 0, len = dec.length / bytes; i < len; i++) {
63 | ar[i] = 0;
64 | for (j = bytes - 1; j >= 0; --j) {
65 | ar[i] += dec.charCodeAt((i * bytes) + j) << (j * 8);
66 | }
67 | }
68 | return ar;
69 | };
70 |
71 | /**
72 | * string to array
73 | * @param {String} input
74 | * @returns {Array} array
75 | */
76 | cc.StringToArray = function (input) {
77 | var tmp = input.split(","), ar = [], i;
78 | for (i = 0; i < tmp.length; i++) {
79 | ar.push(parseInt(tmp[i]));
80 | }
81 | return ar;
82 | };
83 |
--------------------------------------------------------------------------------
/src/cocos2d/physics/CCPhysicsDebugNodeWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | /**
26 | * cc.PhysicsDebugNode's rendering objects of WebGL
27 | */
28 | (function(){
29 | cc.PhysicsDebugNode.WebGLRenderCmd = function (renderableObject) {
30 | cc.Node.WebGLRenderCmd.call(this, renderableObject);
31 | this._needDraw = true;
32 | };
33 |
34 | cc.PhysicsDebugNode.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
35 | cc.PhysicsDebugNode.WebGLRenderCmd.prototype.constructor = cc.PhysicsDebugNode.WebGLRenderCmd;
36 |
37 | cc.PhysicsDebugNode.WebGLRenderCmd.prototype.rendering = function (ctx) {
38 | var node = this._node;
39 | if (!node._space)
40 | return;
41 |
42 | node._space.eachShape(cc.DrawShape.bind(node));
43 | node._space.eachConstraint(cc.DrawConstraint.bind(node));
44 |
45 | //cc.DrawNode.prototype.draw.call(node);
46 | cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
47 | this._shaderProgram.use();
48 | this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
49 | node._render();
50 |
51 | node.clear();
52 | };
53 | })();
--------------------------------------------------------------------------------
/src/cocos2d/physics/CCPhysicsDebugNodeCanvasRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | /**
26 | * cc.PhysicsDebugNode's rendering objects of Canvas
27 | */
28 | (function(){
29 | cc.PhysicsDebugNode.CanvasRenderCmd = function(renderableObject){
30 | cc.Node.CanvasRenderCmd.call(this, renderableObject);
31 | this._buffer = renderableObject._buffer;
32 | this._needDraw = true;
33 | };
34 |
35 | var proto = cc.PhysicsDebugNode.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
36 | proto.constructor = cc.PhysicsDebugNode.CanvasRenderCmd;
37 |
38 | proto.rendering = function(ctx, scaleX, scaleY){
39 | var node = this._node;
40 | if (!node._space)
41 | return;
42 | node._space.eachShape(cc.DrawShape.bind(node));
43 | node._space.eachConstraint(cc.DrawConstraint.bind(node));
44 | cc.DrawNode.CanvasRenderCmd.prototype.rendering.call(this, ctx, scaleX, scaleY);
45 | node.clear();
46 | };
47 |
48 | proto._drawDot = cc.DrawNode.CanvasRenderCmd.prototype._drawDot;
49 | proto._drawSegment = cc.DrawNode.CanvasRenderCmd.prototype._drawSegment;
50 | proto._drawPoly = cc.DrawNode.CanvasRenderCmd.prototype._drawPoly;
51 |
52 | })();
53 |
--------------------------------------------------------------------------------
/src/cocos2d/core/scenes/CCScene.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 |
28 | /**
29 | * cc.Scene is a subclass of cc.Node that is used only as an abstract concept.
30 | * cc.Scene an cc.Node are almost identical with the difference that cc.Scene has it's
31 | * anchor point (by default) at the center of the screen.
32 | *
33 | * For the moment cc.Scene has no other logic than that, but in future releases it might have
34 | * additional logic.
35 | *
36 | * It is a good practice to use and cc.Scene as the parent of all your nodes.
37 | * @class
38 | * @extends cc.Node
39 | * @example
40 | * var scene = new cc.Scene();
41 | */
42 | cc.Scene = cc.Node.extend(/** @lends cc.Scene# */{
43 | /**
44 | * Constructor of cc.Scene
45 | */
46 | _className:"Scene",
47 | ctor:function () {
48 | cc.Node.prototype.ctor.call(this);
49 | this._ignoreAnchorPointForPosition = true;
50 | this.setAnchorPoint(0.5, 0.5);
51 | this.setContentSize(cc.director.getWinSize());
52 | }
53 | });
54 |
55 | /**
56 | * creates a scene
57 | * @deprecated since v3.0,please use new cc.Scene() instead.
58 | * @return {cc.Scene}
59 | */
60 | cc.Scene.create = function () {
61 | return new cc.Scene();
62 | };
63 |
--------------------------------------------------------------------------------
/src/js/gamePlay/sprite/rabbitSprite.js:
--------------------------------------------------------------------------------
1 | var RabbitSprite = cc.Sprite.extend({
2 |
3 | ctor: function () {
4 | this._super();
5 | //this._rect = cc.rect(0, 0, this.getContentSize().width, this.getContentSize().height);
6 | this.type = GC.rabbit.type;
7 | this.direction = GC.rabbit.direction;
8 | this.basket = GC.rabbit.basket;
9 | this.step = GC.rabbit.step[this.direction];
10 | this.moving = GC.MOVING.STOP;
11 | this.jumping = false;
12 | this.growing = false;
13 | this.jumpSpeed = 0;
14 | this.jumpUp = false;
15 | this.runSpeed = 0;
16 | this.leftCount = 0;
17 | this.rightCount = 0;
18 | this.update();
19 | },
20 | getRabbitFrame: function () {
21 | var frameName = 'rabbit-' + this.type + '-' + this.direction + '-' + this.basket + '-' + this.step + '.png';
22 | var frame = cc.spriteFrameCache.getSpriteFrame(frameName);
23 | return frame;
24 | },
25 |
26 | update: function () {
27 | var frame = this.getRabbitFrame();
28 | this.setSpriteFrame(frame);
29 | },
30 | playWin: function () {
31 | var rabbitWin = new RabbitWinSprite();
32 | rabbitWin.x = this.x;
33 | rabbitWin.y = this.y;
34 | rabbitWin.play();
35 | g_GPTouchLayer.texRabbitWinBatch.addChild(rabbitWin);
36 | this.destroy();
37 | },
38 | playLose: function () {
39 | var rabbitLose = new RabbitLoseSprite();
40 | rabbitLose.x = this.x;
41 | rabbitLose.y = this.y;
42 | rabbitLose.play();
43 | g_GPTouchLayer.texRabbitLoseBatch.addChild(rabbitLose);
44 | this.destroy();
45 | },
46 | hurt: function (moonCake) {
47 | if (moonCake.type === GC.CAKE.BOOM) {
48 | var explosion = new ExplosionSprite();
49 | explosion.x = moonCake.x;
50 | explosion.y = moonCake.y;
51 | explosion.play();
52 | g_GPTouchLayer.texExplosionBatch.addChild(explosion);
53 | } else {
54 | var plus = PlusSprite.getOrCreatePlus(moonCake.value);
55 | plus.x = moonCake.x;
56 | plus.y = moonCake.y;
57 | var actionTo = cc.moveTo(0.3, cc.p(plus.x, plus.y + 80));
58 | var actionFadeOut = cc.fadeOut(1);
59 | var callback = cc.callFunc(function (plus) {
60 | plus.destroy();
61 | });
62 | plus.runAction(cc.sequence(actionTo, actionFadeOut, callback));
63 | g_GPTouchLayer.texIconsBatch.addChild(plus);
64 |
65 | if (GC.musicOn) {
66 | cc.audioEngine.playEffect(res.cake_music);
67 | }
68 | }
69 | },
70 | collideRect: function (x, y) {
71 | var w = this.width, h = this.height;
72 | return cc.rect(x - w / 2, y - h / 2, w, h);
73 | },
74 | destroy: function () {
75 | this.visible = false;
76 | }
77 |
78 | });
79 |
--------------------------------------------------------------------------------
/src/cocos2d/core/support/TransformUtils.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2009 Valentin Milea
6 |
7 | http://www.cocos2d-x.org
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy
10 | of this software and associated documentation files (the "Software"), to deal
11 | in the Software without restriction, including without limitation the rights
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | copies of the Software, and to permit persons to whom the Software is
14 | furnished to do so, subject to the following conditions:
15 |
16 | The above copyright notice and this permission notice shall be included in
17 | all copies or substantial portions of the Software.
18 |
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | THE SOFTWARE.
26 | ****************************************************************************/
27 |
28 | /**
29 | * convert an affine transform object to a kmMat4 object
30 | * @param {cc.AffineTransform} trans
31 | * @param {cc.kmMat4} mat
32 | * @function
33 | */
34 | cc.CGAffineToGL = function (trans, mat) {
35 | // | m[0] m[4] m[8] m[12] | | m11 m21 m31 m41 | | a c 0 tx |
36 | // | m[1] m[5] m[9] m[13] | | m12 m22 m32 m42 | | b d 0 ty |
37 | // | m[2] m[6] m[10] m[14] | <=> | m13 m23 m33 m43 | <=> | 0 0 1 0 |
38 | // | m[3] m[7] m[11] m[15] | | m14 m24 m34 m44 | | 0 0 0 1 |
39 | mat[2] = mat[3] = mat[6] = mat[7] = mat[8] = mat[9] = mat[11] = mat[14] = 0.0;
40 | mat[10] = mat[15] = 1.0;
41 | mat[0] = trans.a;
42 | mat[4] = trans.c;
43 | mat[12] = trans.tx;
44 | mat[1] = trans.b;
45 | mat[5] = trans.d;
46 | mat[13] = trans.ty;
47 | };
48 |
49 | /**
50 | * Convert a kmMat4 object to an affine transform object
51 | * @param {cc.kmMat4} mat
52 | * @param {cc.AffineTransform} trans
53 | * @function
54 | */
55 | cc.GLToCGAffine = function (mat, trans) {
56 | trans.a = mat[0];
57 | trans.c = mat[4];
58 | trans.tx = mat[12];
59 | trans.b = mat[1];
60 | trans.d = mat[5];
61 | trans.ty = mat[13];
62 | };
63 |
--------------------------------------------------------------------------------
/src/cocos2d/core/sprites/SpritesPropertyDefine.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | cc._tmp.PrototypeSprite = function () {
28 | var _p = cc.Sprite.prototype;
29 |
30 | // Override properties
31 | cc.defineGetterSetter(_p, "opacityModifyRGB", _p.isOpacityModifyRGB, _p.setOpacityModifyRGB);
32 | cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity);
33 | cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor);
34 |
35 | // Extended properties
36 | /** @expose */
37 | _p.dirty;
38 | /** @expose */
39 | _p.flippedX;
40 | cc.defineGetterSetter(_p, "flippedX", _p.isFlippedX, _p.setFlippedX);
41 | /** @expose */
42 | _p.flippedY;
43 | cc.defineGetterSetter(_p, "flippedY", _p.isFlippedY, _p.setFlippedY);
44 | /** @expose */
45 | _p.offsetX;
46 | cc.defineGetterSetter(_p, "offsetX", _p._getOffsetX);
47 | /** @expose */
48 | _p.offsetY;
49 | cc.defineGetterSetter(_p, "offsetY", _p._getOffsetY);
50 | /** @expose */
51 | _p.atlasIndex;
52 | /** @expose */
53 | _p.texture;
54 | cc.defineGetterSetter(_p, "texture", _p.getTexture, _p.setTexture);
55 | /** @expose */
56 | _p.textureRectRotated;
57 | cc.defineGetterSetter(_p, "textureRectRotated", _p.isTextureRectRotated);
58 | /** @expose */
59 | _p.textureAtlas;
60 | /** @expose */
61 | _p.batchNode;
62 | cc.defineGetterSetter(_p, "batchNode", _p.getBatchNode, _p.setBatchNode);
63 | /** @expose */
64 | _p.quad;
65 | cc.defineGetterSetter(_p, "quad", _p.getQuad);
66 |
67 | };
68 |
--------------------------------------------------------------------------------
/src/image/explosion.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | frames
6 |
7 | explosion-1.png
8 |
9 | frame
10 | {{2,82},{88,72}}
11 | offset
12 | {0,0}
13 | rotated
14 |
15 | sourceColorRect
16 | {{0,0},{88,72}}
17 | sourceSize
18 | {88,72}
19 |
20 | explosion-2.png
21 |
22 | frame
23 | {{104,2},{88,78}}
24 | offset
25 | {0,0}
26 | rotated
27 |
28 | sourceColorRect
29 | {{0,0},{88,78}}
30 | sourceSize
31 | {88,78}
32 |
33 | explosion-3.png
34 |
35 | frame
36 | {{2,2},{100,78}}
37 | offset
38 | {0,0}
39 | rotated
40 |
41 | sourceColorRect
42 | {{0,0},{100,78}}
43 | sourceSize
44 | {100,78}
45 |
46 | explosion-4.png
47 |
48 | frame
49 | {{194,2},{62,59}}
50 | offset
51 | {0,0}
52 | rotated
53 |
54 | sourceColorRect
55 | {{0,0},{62,59}}
56 | sourceSize
57 | {62,59}
58 |
59 |
60 | metadata
61 |
62 | format
63 | 2
64 | realTextureFileName
65 | explosion.png
66 | size
67 | {256,256}
68 | smartupdate
69 | $TexturePacker:SmartUpdate:b2b5b5ece8d3fb8435cabee8e12c1c86:5f2b7ccf5b415615c0d5e5706156496d:c5a2c42043f2b0dda1e7e7adb0cc6144$
70 | textureFileName
71 | explosion.png
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/src/cocos2d/parallax/CCParallaxNodeRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | //TODO find a way to simple these code.
26 |
27 | (function(){
28 | cc.ParallaxNode.CanvasRenderCmd = function(renderable){
29 | cc.Node.CanvasRenderCmd.call(this, renderable);
30 | this._needDraw = false;
31 | };
32 |
33 | var proto = cc.ParallaxNode.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
34 | proto.constructor = cc.ParallaxNode.CanvasRenderCmd;
35 |
36 | proto.updateStatus = function(){
37 | this._node._updateParallaxPosition();
38 | cc.Node.CanvasRenderCmd.prototype.updateStatus.call(this);
39 | };
40 |
41 | proto._syncStatus = function(parentCmd){
42 | this._node._updateParallaxPosition();
43 | cc.Node.CanvasRenderCmd.prototype._syncStatus.call(this, parentCmd);
44 | }
45 | })();
46 |
47 | (function(){
48 | if(cc._renderType !== cc._RENDER_TYPE_WEBGL)
49 | return;
50 |
51 | cc.ParallaxNode.WebGLRenderCmd = function(renderable){
52 | cc.Node.WebGLRenderCmd.call(this, renderable);
53 | this._needDraw = false;
54 | };
55 |
56 | var proto = cc.ParallaxNode.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
57 | proto.constructor = cc.ParallaxNode.WebGLRenderCmd;
58 |
59 | proto.updateStatus = function(){
60 | this._node._updateParallaxPosition();
61 | cc.Node.WebGLRenderCmd.prototype.updateStatus.call(this);
62 | };
63 |
64 | proto._syncStatus = function(parentCmd){
65 | this._node._updateParallaxPosition();
66 | cc.Node.WebGLRenderCmd.prototype._syncStatus.call(this, parentCmd);
67 | }
68 | })();
69 |
70 |
--------------------------------------------------------------------------------
/src/cocos2d/tilemap/CCTMXLayerWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function(){
26 | cc.TMXLayer.WebGLRenderCmd = function(renderableObject){
27 | cc.SpriteBatchNode.WebGLRenderCmd.call(this, renderableObject);
28 | this._needDraw = true;
29 | };
30 |
31 | var proto = cc.TMXLayer.WebGLRenderCmd.prototype = Object.create(cc.SpriteBatchNode.WebGLRenderCmd.prototype);
32 | proto.constructor = cc.TMXLayer.WebGLRenderCmd;
33 |
34 | proto._updateCacheContext = function(){};
35 |
36 | proto.initImageSize = function(){
37 | var node = this._node;
38 | node.tileset.imageSize = this._textureAtlas.texture.getContentSizeInPixels();
39 |
40 | // By default all the tiles are aliased
41 | // pros:
42 | // - easier to render
43 | // cons:
44 | // - difficult to scale / rotate / etc.
45 | this._textureAtlas.texture.setAliasTexParameters();
46 | };
47 |
48 | proto._reusedTileWithRect = function(rect){
49 | var node = this._node;
50 | if (!node._reusedTile) {
51 | node._reusedTile = new cc.Sprite();
52 | node._reusedTile.initWithTexture(node.texture, rect, false);
53 | node._reusedTile.batchNode = node;
54 | } else {
55 | // XXX HACK: Needed because if "batch node" is nil,
56 | // then the Sprite'squad will be reset
57 | node._reusedTile.batchNode = null;
58 |
59 | // Re-init the sprite
60 | node._reusedTile.setTextureRect(rect, false);
61 |
62 | // restore the batch node
63 | node._reusedTile.batchNode = node;
64 | }
65 | return node._reusedTile;
66 | };
67 | })();
68 |
--------------------------------------------------------------------------------
/src/cocos2d/core/sprites/CCBakeSprite.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of _t software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | /**
26 | * cc.BakeSprite is a type of sprite that will be cached.
27 | * @class
28 | * @extend cc.Sprite
29 | */
30 | cc.BakeSprite = cc.Sprite.extend(/** @lends cc.BakeSprite# */{
31 | _cacheCanvas: null,
32 | _cacheContext: null,
33 |
34 | ctor: function(){
35 | cc.Sprite.prototype.ctor.call(this);
36 | var canvasElement = document.createElement("canvas");
37 | canvasElement.width = canvasElement.height = 10;
38 | this._cacheCanvas = canvasElement;
39 | this._cacheContext = new cc.CanvasContextWrapper(canvasElement.getContext("2d"));
40 |
41 | var texture = new cc.Texture2D();
42 | texture.initWithElement(canvasElement);
43 | texture.handleLoadedTexture();
44 | this.setTexture(texture);
45 | },
46 |
47 | getCacheContext: function(){
48 | return this._cacheContext;
49 | },
50 |
51 | getCacheCanvas: function(){
52 | return this._cacheCanvas;
53 | },
54 |
55 | /**
56 | * reset the cache canvas size
57 | * @param {cc.Size|Number} sizeOrWidth size or width
58 | * @param {Number} [height]
59 | */
60 | resetCanvasSize: function(sizeOrWidth, height){
61 | if(height === undefined){
62 | height = sizeOrWidth.height;
63 | sizeOrWidth = sizeOrWidth.width;
64 | }
65 | var locCanvas = this._cacheCanvas;
66 | locCanvas.width = sizeOrWidth;
67 | locCanvas.height = height; //TODO note baidu browser reset the context after set width or height
68 | this.getTexture().handleLoadedTexture();
69 | this.setTextureRect(cc.rect(0,0, sizeOrWidth, height), false);
70 | }
71 | });
72 |
--------------------------------------------------------------------------------
/src/js/connfig/config.js:
--------------------------------------------------------------------------------
1 | var GC = GC || {};
2 |
3 | //游戏难度
4 | GC.DIFFICULTY = {
5 | EASY: 0,
6 | NORMAL: 1
7 | };
8 |
9 | //月饼种类
10 | GC.CAKE = {
11 | BOOM: 0,
12 | SMALL: 1,
13 | NORMAL: 2,
14 | BIG: 3,
15 | HUGE: 4
16 | };
17 |
18 | //兔子大小
19 | GC.RABBIT = {
20 | BIG: 'b',
21 | SMALL: 's'
22 | };
23 |
24 | //道具种类
25 | GC.PROP = {
26 | CLOCK: 'clock',
27 | CARROT: 'carrot',
28 | LESSBOOM: 'lessboom',
29 | BASKET: 'basket'
30 | };
31 |
32 | //兔子移动的方向
33 | GC.MOVING = {
34 | LEFT: 'l',
35 | RIGHT: 'r',
36 | STOP: 's',
37 | UP: 'u'
38 | };
39 |
40 | //游戏状态
41 | GC.GAME_STATE = {
42 | PLAY: 1,
43 | OVER: 2
44 | };
45 |
46 | //游戏结果
47 | GC.GAME_RESULT = {
48 | WIN: 1,
49 | LOSE: 2
50 | };
51 |
52 | //篮子状态
53 | GC.BASKET = {
54 | EMPTY: 1,
55 | LITTLE: 2,
56 | FULL: 3,
57 | OVERFLOW: 4
58 | };
59 |
60 | //键盘按键
61 | GC.KEY_MAP = {
62 | 37: 'l', // Left
63 | 38: 'u', // UP
64 | 39: 'r', // Right
65 | 65: 'l', // A
66 | 87: 'u', // W
67 | 68: 'r' // D
68 | };
69 |
70 | //屏幕尺寸
71 | GC.winSize = cc.size(1000, 600);
72 |
73 | GC.h = GC.winSize.height;
74 |
75 | GC.w = GC.winSize.width;
76 |
77 | GC.w_2 = GC.w / 2;
78 |
79 | GC.h_2 = GC.h / 2;
80 |
81 | //游戏帧频
82 | GC.defaultInterval = 1 / 60;
83 |
84 | //生命值
85 | GC.life = 2;
86 |
87 | //倒计时长
88 | GC.totalTime = 60;
89 |
90 | //游戏难度,指炸弹概率
91 | GC.difficulty = GC.DIFFICULTY.NORMAL;
92 |
93 | //记分牌位数
94 | GC.scoreLen = 7;
95 |
96 | //倒计时位数
97 | GC.timeLen = 2;
98 |
99 | //音乐开关
100 | GC.musicOn = true;
101 |
102 | //兔子相关设置
103 | GC.rabbit = {
104 | x: 600,
105 | y: 50,
106 | maxRunSpeed: 30,
107 | maxJumpSpeed: 30,
108 | direction: GC.MOVING.LEFT,
109 | type: GC.RABBIT.SMALL,
110 | basket: GC.BASKET.EMPTY,
111 | frameLength: 6,
112 | frameInterval: 6,
113 | step: {
114 | l: 3,
115 | r: 4
116 | },
117 | stepJump: {
118 | l: 4,
119 | r: 3
120 | }
121 | };
122 |
123 | //炸弹概率,游戏难度而定
124 | GC.difficultyMap = [0.05, 0.1];
125 |
126 | //月饼下落速度
127 | GC.speedMap = [3, 4, 5, 6];
128 |
129 | //月饼分值
130 | GC.valueMap = [0, 500, 1000, 2000, 5000];
131 |
132 | //篮子可改变的积分值
133 | GC.score = {
134 | little: 20000,
135 | full: 50000,
136 | overflow: 100000
137 | };
138 |
139 | //hao123的位置,参考坐标系是左上角
140 | GC.hao123Map = [
141 | [
142 | [0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [1, 1], [2, 1], [3, 2], [3, 3], [3, 4]
143 | ], //h
144 | [
145 | [4, 2], [4, 3], [5, 1], [5, 4], [6, 1], [6, 4], [7, 1], [7, 2], [7, 3], [7, 4]
146 | ], //a
147 | [
148 | [8, 2], [8, 3], [9, 1], [9, 4], [10, 1], [10, 4], [11, 2], [11, 3]
149 | ], //o
150 | [
151 | [12, 0], [13, 0], [13, 1], [13, 2], [13, 3], [13, 4]
152 | ], //1
153 | [
154 | [14, 0], [14, 3], [14, 4], [15, 0], [15, 2], [15, 4], [16, 0], [16, 2], [16, 4], [17, 1], [17, 4]
155 | ], //2
156 | [
157 | [18, 0], [18, 4], [19, 0], [19, 2], [19, 4], [20, 0], [20, 2], [20, 4], [21, 1], [21, 3]
158 | ]//3
159 | ];
160 |
161 | GC.hao123 = {
162 | speed: 5,
163 | type: 2,
164 | space: 24,
165 | size: 40
166 | }
167 |
--------------------------------------------------------------------------------
/src/cocos2d/kazmath/aabb.js:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2008, Luke Benstead.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification,
9 | are permitted provided that the following conditions are met:
10 |
11 | Redistributions of source code must retain the above copyright notice,
12 | this list of conditions and the following disclaimer.
13 | Redistributions in binary form must reproduce the above copyright notice,
14 | this list of conditions and the following disclaimer in the documentation
15 | and/or other materials provided with the distribution.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | /**
30 | * A structure that represents an axis-aligned bounding box.
31 | * cc.kmAABB => cc.math.AABB
32 | */
33 | cc.math.AABB = function (min, max) {
34 | /** The max corner of the box */
35 | this.min = min || new cc.math.Vec3();
36 | /** The min corner of the box */
37 | this.max = max || new cc.math.Vec3();
38 | };
39 |
40 | /**
41 | * Returns true if point is in the specified AABB, returns false otherwise.
42 | * @param {cc.math.Vec3} point
43 | * @returns {boolean}
44 | */
45 | cc.math.AABB.prototype.containsPoint = function (point) {
46 | return (point.x >= this.min.x && point.x <= this.max.x &&
47 | point.y >= this.min.y && point.y <= this.max.y &&
48 | point.z >= this.min.z && point.z <= this.max.z);
49 | };
50 |
51 | /**
52 | * Returns true if point is in the specified AABB, returns
53 | * false otherwise.
54 | */
55 | cc.math.AABB.containsPoint = function (pPoint, pBox) {
56 | return (pPoint.x >= pBox.min.x && pPoint.x <= pBox.max.x &&
57 | pPoint.y >= pBox.min.y && pPoint.y <= pBox.max.y &&
58 | pPoint.z >= pBox.min.z && pPoint.z <= pBox.max.z);
59 | };
60 |
61 | /**
62 | * Assigns aabb to current AABB object
63 | * @param {cc.math.AABB} aabb
64 | */
65 | cc.math.AABB.prototype.assignFrom = function(aabb){
66 | this.min.assignFrom(aabb.min);
67 | this.max.assignFrom(aabb.max);
68 | };
69 |
70 | /**
71 | * Assigns pIn to pOut, returns pOut.
72 | */
73 | cc.math.AABB.assign = function (pOut, pIn) { //cc.kmAABBAssign
74 | pOut.min.assignFrom(pIn.min);
75 | pOut.max.assignFrom(pIn.max);
76 | return pOut;
77 | };
78 |
79 |
--------------------------------------------------------------------------------
/src/cocos2d/compression/base64.js:
--------------------------------------------------------------------------------
1 | /*--
2 | Copyright 2009-2010 by Stefan Rusterholz.
3 | All rights reserved.
4 | You can choose between MIT and BSD-3-Clause license. License file will be added later.
5 | --*/
6 |
7 | /**
8 | * mixin cc.Codec.Base64
9 | */
10 | cc.Codec.Base64 = {name:'Jacob__Codec__Base64'};
11 |
12 | cc.Codec.Base64._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
13 |
14 | /**
15 | *
16 | * cc.Codec.Base64.decode(input[, unicode=false]) -> String (http://en.wikipedia.org/wiki/Base64).
17 | *
18 | * @function
19 | * @param {String} input The base64 encoded string to decode
20 | * @return {String} Decodes a base64 encoded String
21 | * @example
22 | * //decode string
23 | * cc.Codec.Base64.decode("U29tZSBTdHJpbmc="); // => "Some String"
24 | */
25 | cc.Codec.Base64.decode = function Jacob__Codec__Base64__decode(input) {
26 | var output = [],
27 | chr1, chr2, chr3,
28 | enc1, enc2, enc3, enc4,
29 | i = 0;
30 |
31 | input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
32 |
33 | while (i < input.length) {
34 | enc1 = this._keyStr.indexOf(input.charAt(i++));
35 | enc2 = this._keyStr.indexOf(input.charAt(i++));
36 | enc3 = this._keyStr.indexOf(input.charAt(i++));
37 | enc4 = this._keyStr.indexOf(input.charAt(i++));
38 |
39 | chr1 = (enc1 << 2) | (enc2 >> 4);
40 | chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
41 | chr3 = ((enc3 & 3) << 6) | enc4;
42 |
43 | output.push(String.fromCharCode(chr1));
44 |
45 | if (enc3 !== 64) {
46 | output.push(String.fromCharCode(chr2));
47 | }
48 | if (enc4 !== 64) {
49 | output.push(String.fromCharCode(chr3));
50 | }
51 | }
52 |
53 | output = output.join('');
54 |
55 | return output;
56 | };
57 |
58 | /**
59 | *
60 | * Converts an input string encoded in base64 to an array of integers whose
61 | * values represent the decoded string's characters' bytes.
62 | *
63 | * @function
64 | * @param {String} input The String to convert to an array of Integers
65 | * @param {Number} bytes
66 | * @return {Array}
67 | * @example
68 | * //decode string to array
69 | * var decodeArr = cc.Codec.Base64.decodeAsArray("U29tZSBTdHJpbmc=");
70 | */
71 | cc.Codec.Base64.decodeAsArray = function Jacob__Codec__Base64___decodeAsArray(input, bytes) {
72 | var dec = this.decode(input),
73 | ar = [], i, j, len;
74 | for (i = 0, len = dec.length / bytes; i < len; i++) {
75 | ar[i] = 0;
76 | for (j = bytes - 1; j >= 0; --j) {
77 | ar[i] += dec.charCodeAt((i * bytes) + j) << (j * 8);
78 | }
79 | }
80 |
81 | return ar;
82 | };
83 |
84 | cc.uint8ArrayToUint32Array = function(uint8Arr){
85 | if(uint8Arr.length % 4 !== 0)
86 | return null;
87 |
88 | var arrLen = uint8Arr.length /4;
89 | var retArr = window.Uint32Array? new Uint32Array(arrLen) : [];
90 | for(var i = 0; i < arrLen; i++){
91 | var offset = i * 4;
92 | retArr[i] = uint8Arr[offset] + uint8Arr[offset + 1] * (1 << 8) + uint8Arr[offset + 2] * (1 << 16) + uint8Arr[offset + 3] * (1<<24);
93 | }
94 | return retArr;
95 | };
96 |
--------------------------------------------------------------------------------
/src/cocos2d/particle/CCParticleBatchNodeWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function(){
26 | /**
27 | * cc.ParticleBatchNode's rendering objects of WebGL
28 | */
29 | cc.ParticleBatchNode.WebGLRenderCmd = function(renderable){
30 | cc.Node.WebGLRenderCmd.call(this, renderable);
31 | this._needDraw = true;
32 | };
33 |
34 | var proto = cc.ParticleBatchNode.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
35 | proto.constructor = cc.ParticleBatchNode.WebGLRenderCmd;
36 |
37 | proto.rendering = function (ctx) {
38 | var _t = this._node;
39 | if (_t.textureAtlas.totalQuads === 0)
40 | return;
41 |
42 | this._shaderProgram.use();
43 | this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
44 | cc.glBlendFuncForParticle(_t._blendFunc.src, _t._blendFunc.dst);
45 | _t.textureAtlas.drawQuads();
46 | };
47 |
48 | proto._initWithTexture = function(){
49 | this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR);
50 | };
51 |
52 | proto.visit = function(parentCmd){
53 | var node = this._node;
54 | // CAREFUL:
55 | // This visit is almost identical to cc.Node#visit
56 | // with the exception that it doesn't call visit on it's children
57 | //
58 | // The alternative is to have a void cc.Sprite#visit, but
59 | // although this is less mantainable, is faster
60 | //
61 | if (!node._visible)
62 | return;
63 |
64 | var currentStack = cc.current_stack;
65 | currentStack.stack.push(currentStack.top);
66 | this._syncStatus(parentCmd);
67 | currentStack.top = this._stackMatrix;
68 | //this.draw(ctx);
69 | cc.renderer.pushRenderCommand(this);
70 |
71 | this._dirtyFlag = 0;
72 | cc.kmGLPopMatrix();
73 | };
74 | })();
--------------------------------------------------------------------------------
/src/cocos2d/motion-streak/CCMotionStreakWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | cc.MotionStreak.WebGLRenderCmd = function(renderableObject){
26 | cc.Node.WebGLRenderCmd.call(this, renderableObject);
27 | this._needDraw = true;
28 | this._shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLOR);
29 | };
30 |
31 | cc.MotionStreak.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
32 | cc.MotionStreak.WebGLRenderCmd.prototype.constructor = cc.Sprite.WebGLRenderCmd;
33 |
34 | cc.MotionStreak.WebGLRenderCmd.prototype.rendering = function(ctx){
35 | var node = this._node;
36 | if (node._nuPoints <= 1)
37 | return;
38 |
39 | if (node.texture && node.texture.isLoaded()) {
40 | ctx = ctx || cc._renderContext;
41 | this._shaderProgram.use();
42 | this._shaderProgram._setUniformForMVPMatrixWithMat4(this._stackMatrix);
43 | cc.glEnableVertexAttribs(cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
44 | cc.glBlendFunc(node._blendFunc.src, node._blendFunc.dst);
45 |
46 | cc.glBindTexture2D(node.texture);
47 |
48 | //position
49 | ctx.bindBuffer(ctx.ARRAY_BUFFER, node._verticesBuffer);
50 | ctx.bufferData(ctx.ARRAY_BUFFER, node._vertices, ctx.DYNAMIC_DRAW);
51 | ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, ctx.FLOAT, false, 0, 0);
52 |
53 | //texcoords
54 | ctx.bindBuffer(ctx.ARRAY_BUFFER, node._texCoordsBuffer);
55 | ctx.bufferData(ctx.ARRAY_BUFFER, node._texCoords, ctx.DYNAMIC_DRAW);
56 | ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, ctx.FLOAT, false, 0, 0);
57 |
58 | //colors
59 | ctx.bindBuffer(ctx.ARRAY_BUFFER, node._colorPointerBuffer);
60 | ctx.bufferData(ctx.ARRAY_BUFFER, node._colorPointer, ctx.DYNAMIC_DRAW);
61 | ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, ctx.UNSIGNED_BYTE, true, 0, 0);
62 |
63 | ctx.drawArrays(ctx.TRIANGLE_STRIP, 0, node._nuPoints * 2);
64 | cc.g_NumberOfDraws++;
65 | }
66 | };
--------------------------------------------------------------------------------
/src/cocos2d/kazmath/gl/mat4stack.js:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2008, Luke Benstead.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification,
9 | are permitted provided that the following conditions are met:
10 |
11 | Redistributions of source code must retain the above copyright notice,
12 | this list of conditions and the following disclaimer.
13 | Redistributions in binary form must reproduce the above copyright notice,
14 | this list of conditions and the following disclaimer in the documentation
15 | and/or other materials provided with the distribution.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | (function(cc){
30 | /**
31 | * The stack of cc.math.Matrix4
32 | * @param {cc.math.Matrix4} [top]
33 | * @param {Array} [stack]
34 | * @constructor
35 | */
36 | cc.math.Matrix4Stack = function(top, stack) {
37 | this.top = top;
38 | this.stack = stack || [];
39 | //this._matrixPool = []; // use pool in next version
40 | };
41 | cc.km_mat4_stack = cc.math.Matrix4Stack;
42 | var proto = cc.math.Matrix4Stack.prototype;
43 |
44 | proto.initialize = function() { //cc.km_mat4_stack_initialize
45 | this.stack.length = 0;
46 | this.top = null;
47 | };
48 |
49 | //for compatibility
50 | cc.km_mat4_stack_push = function(stack, item){
51 | stack.stack.push(stack.top);
52 | stack.top = new cc.math.Matrix4(item);
53 | };
54 |
55 | cc.km_mat4_stack_pop = function(stack, pOut){
56 | stack.top = stack.stack.pop();
57 | };
58 |
59 | cc.km_mat4_stack_release = function(stack){
60 | stack.stack = null;
61 | stack.top = null;
62 | };
63 |
64 | proto.push = function(item) {
65 | item = item || this.top;
66 | this.stack.push(this.top);
67 | this.top = new cc.math.Matrix4(item);
68 | //this.top = this._getFromPool(item);
69 | };
70 |
71 | proto.pop = function() {
72 | //this._putInPool(this.top);
73 | this.top = this.stack.pop();
74 | };
75 |
76 | proto.release = function(){
77 | this.stack = null;
78 | this.top = null;
79 | this._matrixPool = null;
80 | };
81 |
82 | proto._getFromPool = function (item) {
83 | var pool = this._matrixPool;
84 | if (pool.length === 0)
85 | return new cc.math.Matrix4(item);
86 | var ret = pool.pop();
87 | ret.assignFrom(item);
88 | return ret;
89 | };
90 |
91 | proto._putInPool = function(matrix){
92 | this._matrixPool.push(matrix);
93 | };
94 | })(cc);
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/src/cocos2d/physics/CCPhysicsSpriteCanvasRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | /**
26 | * cc.PhysicsSprite's rendering objects of Canvas
27 | */
28 | (function(){
29 | cc.PhysicsSprite.CanvasRenderCmd = function(renderableObject){
30 | cc.Sprite.CanvasRenderCmd.call(this, renderableObject);
31 | this._needDraw = true;
32 | };
33 |
34 | var proto = cc.PhysicsSprite.CanvasRenderCmd.prototype = Object.create(cc.Sprite.CanvasRenderCmd.prototype);
35 | proto.constructor = cc.PhysicsSprite.CanvasRenderCmd;
36 |
37 | proto.rendering = function(ctx, scaleX, scaleY){
38 | // This is a special class
39 | // Sprite can not obtain sign
40 | // So here must to calculate of each frame
41 | var node = this._node;
42 | node._syncPosition();
43 | if(!node._ignoreBodyRotation)
44 | node._syncRotation();
45 | this.transform(this.getParentRenderCmd());
46 |
47 | cc.Sprite.CanvasRenderCmd.prototype.rendering.call(this, ctx, scaleX, scaleY);
48 | };
49 |
50 | proto.getNodeToParentTransform = function(){
51 | var node = this._node;
52 |
53 | var t = this._transform;// quick reference
54 | // base position
55 | var locBody = node._body, locScaleX = node._scaleX, locScaleY = node._scaleY, locAnchorPIP = this._anchorPointInPoints;
56 | t.tx = locBody.p.x;
57 | t.ty = locBody.p.y;
58 |
59 | // rotation Cos and Sin
60 | var radians = -locBody.a;
61 | var Cos = 1, Sin = 0;
62 | if (radians && !node._ignoreBodyRotation) {
63 | Cos = Math.cos(radians);
64 | Sin = Math.sin(radians);
65 | }
66 |
67 | // base abcd
68 | t.a = t.d = Cos;
69 | t.b = -Sin;
70 | t.c = Sin;
71 |
72 | // scale
73 | if (locScaleX !== 1 || locScaleY !== 1) {
74 | t.a *= locScaleX;
75 | t.c *= locScaleX;
76 | t.b *= locScaleY;
77 | t.d *= locScaleY;
78 | }
79 |
80 | // adjust anchorPoint
81 | t.tx += Cos * -locAnchorPIP.x * locScaleX + -Sin * locAnchorPIP.y * locScaleY;
82 | t.ty -= Sin * -locAnchorPIP.x * locScaleX + Cos * locAnchorPIP.y * locScaleY;
83 |
84 | // if ignore anchorPoint
85 | if (this._ignoreAnchorPointForPosition) {
86 | t.tx += locAnchorPIP.x;
87 | t.ty += locAnchorPIP.y;
88 | }
89 |
90 | return this._transform;
91 | };
92 |
93 | })();
--------------------------------------------------------------------------------
/src/cocos2d/physics/CCPhysicsSpriteWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | /**
26 | * cc.PhysicsSprite's rendering objects of WebGL
27 | */
28 | (function(){
29 | cc.PhysicsSprite.WebGLRenderCmd = function(renderableObject){
30 | cc.Sprite.WebGLRenderCmd.call(this, renderableObject);
31 | this._needDraw = true;
32 | };
33 |
34 | var proto = cc.PhysicsSprite.WebGLRenderCmd.prototype = Object.create(cc.Sprite.WebGLRenderCmd.prototype);
35 | proto.constructor = cc.PhysicsSprite.WebGLRenderCmd;
36 |
37 | proto.rendering = function(ctx){
38 | // This is a special class
39 | // Sprite can not obtain sign
40 | // So here must to calculate of each frame
41 | var node = this._node;
42 | node._syncPosition();
43 | if(!node._ignoreBodyRotation)
44 | node._syncRotation();
45 | this.transform(this.getParentRenderCmd());
46 |
47 | cc.Sprite.WebGLRenderCmd.prototype.rendering.call(this, ctx);
48 | };
49 |
50 | proto.getNodeToParentTransform = function(){
51 | var node = this._node;
52 | var locBody = node._body, locAnchorPIP = this._anchorPointInPoints, locScaleX = node._scaleX, locScaleY = node._scaleY;
53 | var x = locBody.p.x;
54 | var y = locBody.p.y;
55 |
56 | if (this._ignoreAnchorPointForPosition) {
57 | x += locAnchorPIP.x;
58 | y += locAnchorPIP.y;
59 | }
60 |
61 | // Make matrix
62 | var radians = locBody.a, c = 1, s=0;
63 | if (radians && !node._ignoreBodyRotation) {
64 | c = Math.cos(radians);
65 | s = Math.sin(radians);
66 | }
67 |
68 | // Although scale is not used by physics engines, it is calculated just in case
69 | // the sprite is animated (scaled up/down) using actions.
70 | // For more info see: http://www.cocos2d-iphone.org/forum/topic/68990
71 | if (!cc._rectEqualToZero(locAnchorPIP)) {
72 | x += c * -locAnchorPIP.x * locScaleX + -s * -locAnchorPIP.y * locScaleY;
73 | y += s * -locAnchorPIP.x * locScaleX + c * -locAnchorPIP.y * locScaleY;
74 | }
75 |
76 | // Rot, Translate Matrix
77 | this._transform = cc.affineTransformMake(c * locScaleX, s * locScaleX,
78 | -s * locScaleY, c * locScaleY, x, y);
79 |
80 | return this._transform;
81 | };
82 |
83 | proto.updateTransform = function(){
84 | this._dirty = this._node.isDirty();
85 | cc.Sprite.WebGLRenderCmd.prototype.updateTransform.call(this);
86 | };
87 | })();
--------------------------------------------------------------------------------
/src/cocos2d/labels/CCLabelBMFontWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 |
26 | Use any of these editors to generate BMFonts:
27 | http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
28 | http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
29 | http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
30 | http://www.angelcode.com/products/bmfont/ (Free, Windows only)
31 | ****************************************************************************/
32 |
33 | (function(){
34 | cc.LabelBMFont.WebGLRenderCmd = function(renderableObject){
35 | cc.SpriteBatchNode.WebGLRenderCmd.call(this, renderableObject);
36 | this._needDraw = true;
37 | };
38 |
39 | var proto = cc.LabelBMFont.WebGLRenderCmd.prototype = Object.create(cc.SpriteBatchNode.WebGLRenderCmd.prototype);
40 | proto.constructor = cc.LabelBMFont.WebGLRenderCmd;
41 |
42 | proto._updateCharTexture = function(fontChar, rect, key){
43 | // updating previous sprite
44 | fontChar.setTextureRect(rect, false);
45 | // restore to default in case they were modified
46 | fontChar.visible = true;
47 | };
48 |
49 |
50 | proto._updateFntFileTexture = function(){};
51 |
52 | proto._changeTextureColor = function(){};
53 |
54 | proto._updateChildrenDisplayedOpacity = function(locChild){
55 | locChild.updateDisplayedOpacity(this._displayedOpacity);
56 | };
57 |
58 | proto._updateChildrenDisplayedColor = function(locChild){
59 | locChild.updateDisplayedColor(this._displayedColor);
60 | };
61 |
62 | proto._initBatchTexture = function(){
63 | var node = this._node;
64 | var locTexture = node.textureAtlas.texture;
65 | node._opacityModifyRGB = locTexture.hasPremultipliedAlpha();
66 |
67 | var reusedChar = node._reusedChar = new cc.Sprite();
68 | reusedChar.initWithTexture(locTexture, cc.rect(0, 0, 0, 0), false);
69 | reusedChar.batchNode = node;
70 | };
71 |
72 | proto.rendering = function(ctx){
73 | cc.SpriteBatchNode.WebGLRenderCmd.prototype.rendering.call(this, ctx);
74 |
75 | var node = this._node;
76 | //LabelBMFont - Debug draw
77 | if (cc.LABELBMFONT_DEBUG_DRAW) {
78 | var size = node.getContentSize();
79 | var pos = cc.p(0 | ( -this._anchorPointInPoints.x), 0 | ( -this._anchorPointInPoints.y));
80 | var vertices = [cc.p(pos.x, pos.y), cc.p(pos.x + size.width, pos.y), cc.p(pos.x + size.width, pos.y + size.height), cc.p(pos.x, pos.y + size.height)];
81 | cc._drawingUtil.setDrawColor(0, 255, 0, 255);
82 | cc._drawingUtil.drawPoly(vertices, 4, true);
83 | }
84 | };
85 |
86 | proto._updateCharColorAndOpacity = function(){};
87 | })();
--------------------------------------------------------------------------------
/src/cocos2d/core/labelttf/LabelTTFPropertyDefine.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 |
28 | cc._tmp.PrototypeLabelTTF = function () {
29 | var _p = cc.LabelTTF.prototype;
30 |
31 | // Override properties
32 | cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor);
33 | cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity);
34 |
35 | // Extended properties
36 | /** @expose */
37 | _p.string;
38 | cc.defineGetterSetter(_p, "string", _p.getString, _p.setString);
39 | /** @expose */
40 | _p.textAlign;
41 | cc.defineGetterSetter(_p, "textAlign", _p.getHorizontalAlignment, _p.setHorizontalAlignment);
42 | /** @expose */
43 | _p.verticalAlign;
44 | cc.defineGetterSetter(_p, "verticalAlign", _p.getVerticalAlignment, _p.setVerticalAlignment);
45 | /** @expose */
46 | _p.fontSize;
47 | cc.defineGetterSetter(_p, "fontSize", _p.getFontSize, _p.setFontSize);
48 | /** @expose */
49 | _p.fontName;
50 | cc.defineGetterSetter(_p, "fontName", _p.getFontName, _p.setFontName);
51 | /** @expose */
52 | _p.font;
53 | cc.defineGetterSetter(_p, "font", _p._getFont, _p._setFont);
54 | /** @expose */
55 | _p.boundingSize;
56 | //cc.defineGetterSetter(_p, "boundingSize", _p.getDimensions, _p.setDimensions);
57 | /** @expose */
58 | _p.boundingWidth;
59 | cc.defineGetterSetter(_p, "boundingWidth", _p._getBoundingWidth, _p._setBoundingWidth);
60 | /** @expose */
61 | _p.boundingHeight;
62 | cc.defineGetterSetter(_p, "boundingHeight", _p._getBoundingHeight, _p._setBoundingHeight);
63 | /** @expose */
64 | _p.fillStyle;
65 | cc.defineGetterSetter(_p, "fillStyle", _p._getFillStyle, _p.setFontFillColor);
66 | /** @expose */
67 | _p.strokeStyle;
68 | cc.defineGetterSetter(_p, "strokeStyle", _p._getStrokeStyle, _p._setStrokeStyle);
69 | /** @expose */
70 | _p.lineWidth;
71 | cc.defineGetterSetter(_p, "lineWidth", _p._getLineWidth, _p._setLineWidth);
72 | /** @expose */
73 | _p.shadowOffset;
74 | //cc.defineGetterSetter(_p, "shadowOffset", _p._getShadowOffset, _p._setShadowOffset);
75 | /** @expose */
76 | _p.shadowOffsetX;
77 | cc.defineGetterSetter(_p, "shadowOffsetX", _p._getShadowOffsetX, _p._setShadowOffsetX);
78 | /** @expose */
79 | _p.shadowOffsetY;
80 | cc.defineGetterSetter(_p, "shadowOffsetY", _p._getShadowOffsetY, _p._setShadowOffsetY);
81 | /** @expose */
82 | _p.shadowOpacity;
83 | cc.defineGetterSetter(_p, "shadowOpacity", _p._getShadowOpacity, _p._setShadowOpacity);
84 | /** @expose */
85 | _p.shadowBlur;
86 | cc.defineGetterSetter(_p, "shadowBlur", _p._getShadowBlur, _p._setShadowBlur);
87 |
88 | };
--------------------------------------------------------------------------------
/src/cocos2d/core/sprites/CCSpriteBatchNodeCanvasRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function(){
26 | //SpriteBatchNode's canvas render command
27 | cc.SpriteBatchNode.CanvasRenderCmd = function(renderable){
28 | cc.Node.CanvasRenderCmd.call(this, renderable);
29 |
30 | this._texture = null;
31 | this._originalTexture = null;
32 | };
33 |
34 | var proto = cc.SpriteBatchNode.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
35 | proto.constructor = cc.SpriteBatchNode.CanvasRenderCmd;
36 |
37 | proto.checkAtlasCapacity = function(){};
38 |
39 | proto.isValidChild = function(child){
40 | if (!(child instanceof cc.Sprite)) {
41 | cc.log(cc._LogInfos.Sprite_addChild_4);
42 | return false;
43 | }
44 | return true;
45 | };
46 |
47 | proto.initWithTexture = function(texture, capacity){
48 | this._originalTexture = texture;
49 | this._texture = texture;
50 | };
51 |
52 | proto.insertQuad = function(sprite, index){};
53 |
54 | proto.increaseAtlasCapacity = function(){};
55 |
56 | proto.removeQuadAtIndex = function(){};
57 |
58 | proto.removeAllQuads = function(){};
59 |
60 | proto.getTexture = function(){
61 | return this._texture;
62 | };
63 |
64 | proto.setTexture = function(texture){
65 | this._texture = texture;
66 | var locChildren = this._node._children;
67 | for (var i = 0; i < locChildren.length; i++)
68 | locChildren[i].setTexture(texture);
69 | };
70 |
71 | proto.updateChildrenAtlasIndex = function(children){
72 | this._node._descendants.length = 0;
73 | //update _descendants after sortAllChildren
74 | for (var i = 0, len = children.length; i < len; i++)
75 | this._updateAtlasIndex(children[i]);
76 | };
77 |
78 | proto._updateAtlasIndex = function (sprite) {
79 | var locDescendants = this._node._descendants;
80 | var pArray = sprite.children, i, len = pArray.length;
81 | for (i = 0; i < len; i++) {
82 | if (pArray[i]._localZOrder < 0) {
83 | locDescendants.push(pArray[i]);
84 | } else
85 | break
86 | }
87 | locDescendants.push(sprite);
88 | for (; i < len; i++) {
89 | locDescendants.push(pArray[i]);
90 | }
91 | };
92 |
93 | proto.getTextureAtlas = function(){};
94 |
95 | proto.setTextureAtlas = function(textureAtlas){};
96 |
97 | proto.cutting = function(sprite, index){
98 | var node = this._node;
99 | node._children.splice(index, 0, sprite);
100 | }
101 | })();
--------------------------------------------------------------------------------
/gulpfile.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var gulp = require('gulp');
4 | var concat = require('gulp-concat');
5 |
6 | var browserSync = require('browser-sync');
7 | var reload = browserSync.reload;
8 |
9 | var moduleMap = require('./moduleConfig.json').module;
10 |
11 | var path = {
12 | js: 'src/js/**/*.js',
13 | json: 'src/**/*.json',
14 | css: 'src/**/*.css',
15 | html: 'src/**/*.html',
16 | image: 'src/image/**/*',
17 | music: ['src/**/*.mp3', 'src/**/*.ogg']
18 | }
19 |
20 | var dest = 'dest/'
21 |
22 | gulp.task('js:copy', function () {
23 | return gulp.src(path.js)
24 | .pipe(concat('main.js'))
25 | .pipe(gulp.dest(dest + '/js'));
26 | });
27 |
28 | gulp.task('css:copy', function () {
29 | return gulp.src(path.css)
30 | .pipe(gulp.dest(dest));
31 | });
32 |
33 | gulp.task('html:copy', function () {
34 | return gulp.src(path.html)
35 | .pipe(gulp.dest(dest));
36 | });
37 |
38 | gulp.task('image:copy', function () {
39 | return gulp.src(path.image)
40 | .pipe(gulp.dest(dest + '/image'));
41 | });
42 |
43 | gulp.task('music:copy', function () {
44 | return gulp.src(path.music)
45 | .pipe(gulp.dest(dest));
46 | });
47 |
48 | gulp.task('json:copy', function () {
49 | return gulp.src(path.json)
50 | .pipe(gulp.dest(dest));
51 | });
52 |
53 | var jsAddedCache;
54 | gulp.task('cocos2d:compile', function () {
55 | jsAddedCache = {};
56 | var jsList = ['src/cocos2d/CCBoot.js'];
57 | jsList = jsList.concat(getJsListOfModule(moduleMap, 'cocos2d', 'src'));
58 | //console.log(jsList);
59 | return gulp.src(jsList)
60 | .pipe(concat('cocos2d.js'))
61 | .pipe(gulp.dest(dest + '/cocos2d'));
62 | });
63 |
64 |
65 | function getJsListOfModule(moduleMap, moduleName, dir) {
66 | if (jsAddedCache[moduleName])
67 | return null;
68 | dir = dir || "";
69 | var jsList = [];
70 | var tempList = moduleMap[moduleName];
71 | if (!tempList)
72 | throw "can not find module [" + moduleName + "]";
73 | for (var i = 0, li = tempList.length; i < li; i++) {
74 | var item = tempList[i];
75 | if (jsAddedCache[item])
76 | continue;
77 | var ext = extname(item);
78 | if (!ext) {
79 | var arr = getJsListOfModule(moduleMap, item, dir);
80 | if (arr)
81 | jsList = jsList.concat(arr);
82 | }
83 | else if (ext.toLowerCase() == ".js")
84 | jsList.push(join(dir, item));
85 | jsAddedCache[item] = 1;
86 | }
87 | return jsList;
88 | }
89 |
90 | function extname(pathStr) {
91 | var temp = /(\.[^\.\/\?\\]*)(\?.*)?$/.exec(pathStr);
92 | return temp ? temp[1] : null;
93 | }
94 |
95 | function join() {
96 | var l = arguments.length;
97 | var result = "";
98 | for (var i = 0; i < l; i++) {
99 | result = (result + (result == "" ? "" : "/") + arguments[i]).replace(/(\/|\\\\)$/, "");
100 | }
101 | return result;
102 | };
103 |
104 | gulp.task('connect', ['compile'], function () {
105 | browserSync({
106 | notify: false,
107 | port: 9000,
108 | server: {
109 | baseDir: [dest]
110 | }
111 | });
112 |
113 | // watch for changes
114 | gulp.watch(path.js, function () {
115 | gulp.start('js:copy');
116 | reload();
117 | });
118 | gulp.watch(path.css, function () {
119 | gulp.start('css:copy');
120 | reload();
121 | });
122 | gulp.watch(path.html, function () {
123 | gulp.start('html:copy');
124 | reload();
125 | });
126 | gulp.watch(path.image, function () {
127 | gulp.start('image:copy');
128 | reload();
129 | });
130 | gulp.watch(path.json, function () {
131 | gulp.start('json:copy');
132 | reload();
133 | });
134 | gulp.watch(path.music, function () {
135 | gulp.start('music:copy');
136 | reload();
137 | });
138 | });
139 |
140 | //clean dest dir
141 | gulp.task('clean', require('del').bind(null, [dest]));
142 |
143 | gulp.task('default', ['clean'], function () {
144 | gulp.start('compile');
145 | });
146 |
147 | gulp.task('compile', ['js:copy', 'css:copy', 'html:copy', 'json:copy', 'music:copy', 'image:copy', 'cocos2d:compile']);
148 |
149 | gulp.task('serve', ['clean'], function () {
150 | gulp.start('connect');
151 | });
152 |
--------------------------------------------------------------------------------
/src/cocos2d/node-grid/CCNodeGridWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function(){
26 | cc.NodeGrid.WebGLRenderCmd = function(renderable){
27 | cc.Node.WebGLRenderCmd.call(this, renderable);
28 | this._needDraw = false;
29 | this._gridBeginCommand = new cc.CustomRenderCmd(this, this.onGridBeginDraw);
30 | this._gridEndCommand = new cc.CustomRenderCmd(this, this.onGridEndDraw);
31 | };
32 |
33 | var proto = cc.NodeGrid.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
34 | proto.constructor = cc.NodeGrid.WebGLRenderCmd;
35 |
36 | proto.visit = function(parentCmd) {
37 | var node = this._node;
38 | // quick return if not visible
39 | if (!node._visible)
40 | return;
41 |
42 | parentCmd = parentCmd || this.getParentRenderCmd();
43 | if (node._parent && node._parent._renderCmd)
44 | this._curLevel = node._parent._renderCmd._curLevel + 1;
45 |
46 | var currentStack = cc.current_stack;
47 | currentStack.stack.push(currentStack.top);
48 | this._syncStatus(parentCmd);
49 | currentStack.top = this._stackMatrix;
50 |
51 | /*var beforeProjectionType = cc.director.PROJECTION_DEFAULT;
52 | if (locGrid && locGrid._active) {
53 | //var backMatrix = new cc.kmMat4();
54 | //cc.kmMat4Assign(backMatrix, this._stackMatrix);
55 |
56 | beforeProjectionType = cc.director.getProjection();
57 | //locGrid.set2DProjection();
58 |
59 | //reset this._stackMatrix to current_stack.top
60 | //cc.kmMat4Assign(currentStack.top, backMatrix);
61 | }*/
62 | cc.renderer.pushRenderCommand(this._gridBeginCommand);
63 |
64 | if (node._target)
65 | node._target.visit();
66 |
67 | var locChildren = node._children;
68 | if (locChildren && locChildren.length > 0) {
69 | var childLen = locChildren.length;
70 | node.sortAllChildren();
71 | // draw children
72 | for (var i = 0; i < childLen; i++) {
73 | var child = locChildren[i];
74 | child && child.visit();
75 | }
76 | }
77 |
78 | //if (locGrid && locGrid._active) {
79 | //cc.director.setProjection(beforeProjectionType);
80 | //}
81 | cc.renderer.pushRenderCommand(this._gridEndCommand);
82 |
83 | this._dirtyFlag = 0;
84 | currentStack.top = currentStack.stack.pop();
85 | };
86 |
87 | proto.onGridBeginDraw = function(){
88 | var locGrid = this._node.grid;
89 | if (locGrid && locGrid._active)
90 | locGrid.beforeDraw();
91 | };
92 |
93 | proto.onGridEndDraw = function(){
94 | var locGrid = this._node.grid;
95 | if (locGrid && locGrid._active)
96 | locGrid.afterDraw(this._node);
97 | };
98 | })();
99 |
--------------------------------------------------------------------------------
/src/cocos2d/core/platform/CCVisibleRect.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | /**
28 | * cc.visibleRect is a singleton object which defines the actual visible rect of the current view,
29 | * it should represent the same rect as cc.view.getViewportRect()
30 | *
31 | * @property {cc.Point} topLeft - Top left coordinate of the screen related to the game scene
32 | * @property {cc.Point} topRight - Top right coordinate of the screen related to the game scene
33 | * @property {cc.Point} top - Top center coordinate of the screen related to the game scene
34 | * @property {cc.Point} bottomLeft - Bottom left coordinate of the screen related to the game scene
35 | * @property {cc.Point} bottomRight - Bottom right coordinate of the screen related to the game scene
36 | * @property {cc.Point} bottom - Bottom center coordinate of the screen related to the game scene
37 | * @property {cc.Point} center - Center coordinate of the screen related to the game scene
38 | * @property {cc.Point} left - Left center coordinate of the screen related to the game scene
39 | * @property {cc.Point} right - Right center coordinate of the screen related to the game scene
40 | * @property {Number} width - Width of the screen
41 | * @property {Number} height - Height of the screen
42 | *
43 | * @class
44 | * @name cc.visibleRect
45 | */
46 | cc.visibleRect = {
47 | topLeft:cc.p(0,0),
48 | topRight:cc.p(0,0),
49 | top:cc.p(0,0),
50 | bottomLeft:cc.p(0,0),
51 | bottomRight:cc.p(0,0),
52 | bottom:cc.p(0,0),
53 | center:cc.p(0,0),
54 | left:cc.p(0,0),
55 | right:cc.p(0,0),
56 | width:0,
57 | height:0,
58 |
59 | /**
60 | * initialize
61 | * @param {cc.Rect} visibleRect
62 | */
63 | init:function(visibleRect){
64 |
65 | var w = this.width = visibleRect.width;
66 | var h = this.height = visibleRect.height;
67 | var l = visibleRect.x,
68 | b = visibleRect.y,
69 | t = b + h,
70 | r = l + w;
71 |
72 | //top
73 | this.topLeft.x = l;
74 | this.topLeft.y = t;
75 | this.topRight.x = r;
76 | this.topRight.y = t;
77 | this.top.x = l + w/2;
78 | this.top.y = t;
79 |
80 | //bottom
81 | this.bottomLeft.x = l;
82 | this.bottomLeft.y = b;
83 | this.bottomRight.x = r;
84 | this.bottomRight.y = b;
85 | this.bottom.x = l + w/2;
86 | this.bottom.y = b;
87 |
88 | //center
89 | this.center.x = l + w/2;
90 | this.center.y = b + h/2;
91 |
92 | //left
93 | this.left.x = l;
94 | this.left.y = b + h/2;
95 |
96 | //right
97 | this.right.x = r;
98 | this.right.y = b + h/2;
99 | }
100 | };
--------------------------------------------------------------------------------
/src/cocos2d/kazmath/vec2.js:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2008, Luke Benstead.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification,
9 | are permitted provided that the following conditions are met:
10 |
11 | Redistributions of source code must retain the above copyright notice,
12 | this list of conditions and the following disclaimer.
13 | Redistributions in binary form must reproduce the above copyright notice,
14 | this list of conditions and the following disclaimer in the documentation
15 | and/or other materials provided with the distribution.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | (function(cc){
30 | cc.math.Vec2 = function (x, y) {
31 | if(y === undefined){
32 | this.x = x.x;
33 | this.y = x.y;
34 | }else{
35 | this.x = x || 0;
36 | this.y = y || 0;
37 | }
38 | };
39 |
40 | var proto = cc.math.Vec2.prototype;
41 | proto.fill = function(x, y){ // = cc.kmVec2Fill
42 | this.x = x;
43 | this.y = y;
44 | };
45 |
46 | proto.length = function(){ // = cc.kmVec2Length
47 | return Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y));
48 | };
49 |
50 | proto.lengthSq = function(){ // = cc.kmVec2LengthSq
51 | return cc.math.square(this.x) + cc.math.square(this.y);
52 | };
53 |
54 | proto.normalize = function(){ // = cc.kmVec2Normalize
55 | var l = 1.0 / this.length();
56 | this.x *= l;
57 | this.y *= l;
58 | return this;
59 | };
60 |
61 | cc.math.Vec2.add = function (pOut, pV1, pV2) { // = cc.kmVec2Add
62 | pOut.x = pV1.x + pV2.x;
63 | pOut.y = pV1.y + pV2.y;
64 | return pOut
65 | };
66 |
67 | proto.add = function(vec){ // = cc.kmVec2Add
68 | this.x += vec.x;
69 | this.y += vec.y;
70 | return this;
71 | };
72 |
73 | proto.dot = function (vec) { //cc.kmVec2Dot
74 | return this.x * vec.x + this.y * vec.y;
75 | };
76 |
77 | cc.math.Vec2.subtract = function (pOut, pV1, pV2) { // = cc.kmVec2Subtract
78 | pOut.x = pV1.x - pV2.x;
79 | pOut.y = pV1.y - pV2.y;
80 | return pOut;
81 | };
82 |
83 | proto.subtract = function(vec){ // = cc.kmVec2Subtract
84 | this.x -= vec.x;
85 | this.y -= vec.y;
86 | return this;
87 | };
88 |
89 | proto.transform = function (mat3) { // = cc.kmVec2Transform
90 | var x = this.x, y = this.y;
91 | this.x = x * mat3.mat[0] + y * mat3.mat[3] + mat3.mat[6];
92 | this.y = x * mat3.mat[1] + y * mat3.mat[4] + mat3.mat[7];
93 | return this;
94 | };
95 |
96 | cc.math.Vec2.scale = function (pOut, pIn, s) { // = cc.kmVec2Scale
97 | pOut.x = pIn.x * s;
98 | pOut.y = pIn.y * s;
99 | return pOut;
100 | };
101 |
102 | proto.scale = function(s) { // = cc.kmVec2Scale
103 | this.x *= s;
104 | this.y *= s;
105 | return this;
106 | };
107 |
108 | proto.equals = function (vec) { // = cc.kmVec2AreEqual
109 | return (this.x < vec.x + cc.math.EPSILON && this.x > vec.x - cc.math.EPSILON) &&
110 | (this.y < vec.y + cc.math.EPSILON && this.y > vec.y - cc.math.EPSILON);
111 | };
112 | })(cc);
113 |
114 |
--------------------------------------------------------------------------------
/src/cocos2d/labels/CCLabelAtlasCanvasRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function(){
26 | cc.LabelAtlas.CanvasRenderCmd = function(renderableObject){
27 | cc.AtlasNode.CanvasRenderCmd.call(this, renderableObject);
28 | this._needDraw = false;
29 | };
30 |
31 | var proto = cc.LabelAtlas.CanvasRenderCmd.prototype = Object.create(cc.AtlasNode.CanvasRenderCmd.prototype);
32 | proto.constructor = cc.LabelAtlas.CanvasRenderCmd;
33 |
34 | proto.setCascade = function(){
35 | var node = this._node;
36 | node._cascadeOpacityEnabled = true;
37 | node._cascadeColorEnabled = false;
38 | };
39 |
40 | proto.updateAtlasValues = function(){
41 | var node = this._node;
42 | var locString = node._string || "";
43 | var n = locString.length;
44 | var texture = this._texture;
45 | var locItemWidth = node._itemWidth , locItemHeight = node._itemHeight; //needn't multiply cc.contentScaleFactor(), because sprite's draw will do this
46 |
47 | for (var i = 0; i < n; i++) {
48 | var a = locString.charCodeAt(i) - node._mapStartChar.charCodeAt(0);
49 | var row = parseInt(a % node._itemsPerRow, 10);
50 | var col = parseInt(a / node._itemsPerRow, 10);
51 |
52 | var rect = cc.rect(row * locItemWidth, col * locItemHeight, locItemWidth, locItemHeight);
53 | var c = locString.charCodeAt(i);
54 | var fontChar = node.getChildByTag(i);
55 | if (!fontChar) {
56 | fontChar = new cc.Sprite();
57 | if (c === 32) {
58 | fontChar.init();
59 | fontChar.setTextureRect(cc.rect(0, 0, 10, 10), false, cc.size(0, 0));
60 | } else
61 | fontChar.initWithTexture(texture, rect);
62 |
63 | cc.Node.prototype.addChild.call(node, fontChar, 0, i);
64 | } else {
65 | if (c === 32) {
66 | fontChar.init();
67 | fontChar.setTextureRect(cc.rect(0, 0, 10, 10), false, cc.size(0, 0));
68 | } else {
69 | // reusing fonts
70 | fontChar.initWithTexture(texture, rect);
71 | // restore to default in case they were modified
72 | fontChar.visible = true;
73 | }
74 | }
75 | fontChar.setPosition(i * locItemWidth + locItemWidth / 2, locItemHeight / 2);
76 | }
77 | };
78 |
79 | proto.setString = function(label){
80 | var node = this._node;
81 | if (node._children) {
82 | var locChildren = node._children;
83 | var len = locChildren.length;
84 | for (var i = 0; i < len; i++) {
85 | var child = locChildren[i];
86 | if (child && !child._lateChild)
87 | child.visible = false;
88 | }
89 | }
90 | };
91 |
92 | proto._addChild = function(){
93 | child._lateChild = true;
94 | };
95 | })();
--------------------------------------------------------------------------------
/src/cocos2d/effects/CCGrabber.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | /**
28 | * FBO class that grabs the the contents of the screen
29 | * @class
30 | * @extends cc.Class
31 | */
32 | cc.Grabber = cc.Class.extend({
33 | _FBO:null,
34 | _oldFBO:null,
35 | _oldClearColor:null,
36 |
37 | _gl:null,
38 |
39 | /**
40 | * constructor of cc.Grabber
41 | */
42 | ctor:function () {
43 | cc._checkWebGLRenderMode();
44 | this._gl = cc._renderContext;
45 | this._oldClearColor = [0, 0, 0, 0];
46 | this._oldFBO = null;
47 | // generate FBO
48 | this._FBO = this._gl.createFramebuffer();
49 | },
50 |
51 | /**
52 | * grab
53 | * @param {cc.Texture2D} texture
54 | */
55 | grab:function (texture) {
56 | var locGL = this._gl;
57 | this._oldFBO = locGL.getParameter(locGL.FRAMEBUFFER_BINDING);
58 | // bind
59 | locGL.bindFramebuffer(locGL.FRAMEBUFFER, this._FBO);
60 | // associate texture with FBO
61 | locGL.framebufferTexture2D(locGL.FRAMEBUFFER, locGL.COLOR_ATTACHMENT0, locGL.TEXTURE_2D, texture._webTextureObj, 0);
62 |
63 | // check if it worked (probably worth doing :) )
64 | var status = locGL.checkFramebufferStatus(locGL.FRAMEBUFFER);
65 | if (status !== locGL.FRAMEBUFFER_COMPLETE)
66 | cc.log("Frame Grabber: could not attach texture to frmaebuffer");
67 | locGL.bindFramebuffer(locGL.FRAMEBUFFER, this._oldFBO);
68 | },
69 |
70 | /**
71 | * should be invoked before drawing
72 | * @param {cc.Texture2D} texture
73 | */
74 | beforeRender:function (texture) {
75 | var locGL = this._gl;
76 | this._oldFBO = locGL.getParameter(locGL.FRAMEBUFFER_BINDING);
77 | locGL.bindFramebuffer(locGL.FRAMEBUFFER, this._FBO);
78 |
79 | // save clear color
80 | this._oldClearColor = locGL.getParameter(locGL.COLOR_CLEAR_VALUE);
81 |
82 | // BUG XXX: doesn't work with RGB565.
83 | locGL.clearColor(0, 0, 0, 0);
84 |
85 | // BUG #631: To fix #631, uncomment the lines with #631
86 | // Warning: But it CCGrabber won't work with 2 effects at the same time
87 | // glClearColor(0.0f,0.0f,0.0f,1.0f); // #631
88 |
89 | locGL.clear(locGL.COLOR_BUFFER_BIT | locGL.DEPTH_BUFFER_BIT);
90 |
91 | // glColorMask(true, true, true, false); // #631
92 | },
93 |
94 | /**
95 | * should be invoked after drawing
96 | * @param {cc.Texture2D} texture
97 | */
98 | afterRender:function (texture) {
99 | var locGL = this._gl;
100 | locGL.bindFramebuffer(locGL.FRAMEBUFFER, this._oldFBO);
101 | locGL.colorMask(true, true, true, true); // #631
102 | },
103 |
104 | /**
105 | * delete FBO
106 | */
107 | destroy:function(){
108 | this._gl.deleteFramebuffer(this._FBO);
109 | }
110 | });
111 |
--------------------------------------------------------------------------------
/src/cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | (function(){
26 | cc.RenderTexture.CanvasRenderCmd = function(renderableObject){
27 | cc.Node.CanvasRenderCmd.call(this, renderableObject);
28 | this._needDraw = true;
29 | this._clearColorStr = "rgba(255,255,255,1)";
30 |
31 | this._cacheCanvas = cc.newElement('canvas');
32 | this._cacheContext = new cc.CanvasContextWrapper(this._cacheCanvas.getContext('2d'));
33 | };
34 |
35 | var proto = cc.RenderTexture.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
36 | proto.constructor = cc.RenderTexture.CanvasRenderCmd;
37 |
38 | proto.cleanup = function(){
39 | this._cacheContext = null;
40 | this._cacheCanvas = null;
41 | };
42 |
43 | proto.clearStencil = function (stencilValue) { };
44 |
45 | proto.setVirtualViewport = function(rtBegin, fullRect, fullViewport) {};
46 |
47 | proto.updateClearColor = function(clearColor){
48 | this._clearColorStr = "rgba(" + (0 | clearColor.r) + "," + (0 | clearColor.g) + "," + (0 | clearColor.b) + "," + clearColor.a / 255 + ")";
49 | };
50 |
51 | proto.initWithWidthAndHeight = function(width, height, format, depthStencilFormat){
52 | var node = this._node;
53 | var locCacheCanvas = this._cacheCanvas, locScaleFactor = cc.contentScaleFactor();
54 | locCacheCanvas.width = 0 | (width * locScaleFactor);
55 | locCacheCanvas.height = 0 | (height * locScaleFactor);
56 |
57 | var texture = new cc.Texture2D();
58 | texture.initWithElement(locCacheCanvas);
59 | texture.handleLoadedTexture();
60 |
61 | var locSprite = node.sprite = new cc.Sprite(texture);
62 | locSprite.setBlendFunc(cc.ONE, cc.ONE_MINUS_SRC_ALPHA);
63 | // Disabled by default.
64 | node.autoDraw = false;
65 | // add sprite for backward compatibility
66 | node.addChild(locSprite);
67 | return true;
68 | };
69 |
70 | proto.begin = function(){};
71 |
72 | proto._beginWithClear = function(r, g, b, a, depthValue, stencilValue, flags){
73 | r = r || 0;
74 | g = g || 0;
75 | b = b || 0;
76 | a = isNaN(a) ? 255 : a;
77 |
78 | var context = this._cacheContext.getContext();
79 | var locCanvas = this._cacheCanvas;
80 | context.setTransform(1,0,0,1,0,0);
81 | this._cacheContext.setFillStyle("rgba(" + (0 | r) + "," + (0 | g) + "," + (0 | b) + "," + a / 255 + ")");
82 | context.clearRect(0, 0, locCanvas.width, locCanvas.height);
83 | context.fillRect(0, 0, locCanvas.width, locCanvas.height);
84 | };
85 |
86 | proto.end = function(){
87 | var node = this._node;
88 |
89 | var scale = cc.contentScaleFactor();
90 | cc.renderer._renderingToCacheCanvas(this._cacheContext, node.__instanceId, scale, scale);
91 | };
92 |
93 | proto.clearRect = function(x, y, width, height){
94 | this._cacheContext.clearRect(x, y, width, -height);
95 | };
96 |
97 | proto.clearDepth = function(depthValue){
98 | cc.log("clearDepth isn't supported on Cocos2d-Html5");
99 | };
100 |
101 | proto.visit = function(parentCmd){
102 | var node = this._node;
103 | this._syncStatus(parentCmd);
104 | node.sprite.visit(this);
105 | this._dirtyFlag = 0;
106 | };
107 | })();
--------------------------------------------------------------------------------
/src/cocos2d/core/event-manager/CCEventExtension.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | /**
27 | * The acceleration event
28 | * @class
29 | * @extends cc.Event
30 | */
31 | cc.EventAcceleration = cc.Event.extend(/** @lends cc.EventAcceleration# */{
32 | _acc: null,
33 | ctor: function (acc) {
34 | cc.Event.prototype.ctor.call(this, cc.Event.ACCELERATION);
35 | this._acc = acc;
36 | }
37 | });
38 |
39 | /**
40 | * The keyboard event
41 | * @class
42 | * @extends cc.Event
43 | */
44 | cc.EventKeyboard = cc.Event.extend(/** @lends cc.EventKeyboard# */{
45 | _keyCode: 0,
46 | _isPressed: false,
47 | ctor: function (keyCode, isPressed) {
48 | cc.Event.prototype.ctor.call(this, cc.Event.KEYBOARD);
49 | this._keyCode = keyCode;
50 | this._isPressed = isPressed;
51 | }
52 | });
53 |
54 |
55 | //Acceleration
56 | cc._EventListenerAcceleration = cc.EventListener.extend({
57 | _onAccelerationEvent: null,
58 |
59 | ctor: function (callback) {
60 | this._onAccelerationEvent = callback;
61 | var selfPointer = this;
62 | var listener = function (event) {
63 | selfPointer._onAccelerationEvent(event._acc, event);
64 | };
65 | cc.EventListener.prototype.ctor.call(this, cc.EventListener.ACCELERATION, cc._EventListenerAcceleration.LISTENER_ID, listener);
66 | },
67 |
68 | checkAvailable: function () {
69 |
70 | cc.assert(this._onAccelerationEvent, cc._LogInfos._EventListenerAcceleration_checkAvailable);
71 |
72 | return true;
73 | },
74 |
75 | clone: function () {
76 | return new cc._EventListenerAcceleration(this._onAccelerationEvent);
77 | }
78 | });
79 |
80 | cc._EventListenerAcceleration.LISTENER_ID = "__cc_acceleration";
81 |
82 | cc._EventListenerAcceleration.create = function (callback) {
83 | return new cc._EventListenerAcceleration(callback);
84 | };
85 |
86 |
87 | //Keyboard
88 | cc._EventListenerKeyboard = cc.EventListener.extend({
89 | onKeyPressed: null,
90 | onKeyReleased: null,
91 |
92 | ctor: function () {
93 | var selfPointer = this;
94 | var listener = function (event) {
95 | if (event._isPressed) {
96 | if (selfPointer.onKeyPressed)
97 | selfPointer.onKeyPressed(event._keyCode, event);
98 | } else {
99 | if (selfPointer.onKeyReleased)
100 | selfPointer.onKeyReleased(event._keyCode, event);
101 | }
102 | };
103 | cc.EventListener.prototype.ctor.call(this, cc.EventListener.KEYBOARD, cc._EventListenerKeyboard.LISTENER_ID, listener);
104 | },
105 |
106 | clone: function () {
107 | var eventListener = new cc._EventListenerKeyboard();
108 | eventListener.onKeyPressed = this.onKeyPressed;
109 | eventListener.onKeyReleased = this.onKeyReleased;
110 | return eventListener;
111 | },
112 |
113 | checkAvailable: function () {
114 | if (this.onKeyPressed === null && this.onKeyReleased === null) {
115 | cc.log(cc._LogInfos._EventListenerKeyboard_checkAvailable);
116 | return false;
117 | }
118 | return true;
119 | }
120 | });
121 |
122 | cc._EventListenerKeyboard.LISTENER_ID = "__cc_keyboard";
123 |
124 | cc._EventListenerKeyboard.create = function () {
125 | return new cc._EventListenerKeyboard();
126 | };
--------------------------------------------------------------------------------
/src/cocos2d/core/labelttf/CCLabelTTFWebGLRenderCmd.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | // ----------------------------------- LabelTTF WebGL render cmd ----------------------------
26 | (function() {
27 | cc.LabelTTF.WebGLRenderCmd = function (renderable) {
28 | cc.Sprite.WebGLRenderCmd.call(this, renderable);
29 | cc.LabelTTF.RenderCmd.call(this);
30 | this.setShaderProgram(cc.shaderCache.programForKey(cc.LabelTTF._SHADER_PROGRAM));
31 | };
32 |
33 | var proto = cc.LabelTTF.WebGLRenderCmd.prototype = Object.create(cc.Sprite.WebGLRenderCmd.prototype);
34 | cc.inject(cc.LabelTTF.RenderCmd.prototype, proto); //multi-inherit
35 | proto.constructor = cc.LabelTTF.WebGLRenderCmd;
36 |
37 | proto._setColorsString = function () {
38 | this.setDirtyFlag(cc.Node._dirtyFlags.textDirty);
39 | var node = this._node;
40 | var locStrokeColor = node._strokeColor, locFontFillColor = node._textFillColor;
41 | this._shadowColorStr = "rgba(128,128,128," + node._shadowOpacity + ")";
42 | this._fillColorStr = "rgba(" + (0 | locFontFillColor.r) + "," + (0 | locFontFillColor.g) + "," + (0 | locFontFillColor.b) + ", 1)";
43 | this._strokeColorStr = "rgba(" + (0 | locStrokeColor.r) + "," + (0 | locStrokeColor.g) + "," + (0 | locStrokeColor.b) + ", 1)";
44 | };
45 |
46 | proto.updateStatus = function () {
47 | var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
48 | var colorDirty = locFlag & flags.colorDirty,
49 | opacityDirty = locFlag & flags.opacityDirty;
50 |
51 | if (colorDirty)
52 | this._updateDisplayColor();
53 | if (opacityDirty)
54 | this._updateDisplayOpacity();
55 |
56 | if(colorDirty || opacityDirty){
57 | this._setColorsString();
58 | this._updateColor();
59 | this._updateTexture();
60 | }else if(locFlag & flags.textDirty)
61 | this._updateTexture();
62 |
63 | if (this._dirtyFlag & flags.transformDirty){
64 | this.transform(this.getParentRenderCmd(), true);
65 | this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.transformDirty ^ this._dirtyFlag;
66 | }
67 | };
68 |
69 | proto._syncStatus = function (parentCmd) {
70 | var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
71 | var parentNode = parentCmd ? parentCmd._node : null;
72 |
73 | if(parentNode && parentNode._cascadeColorEnabled && (parentCmd._dirtyFlag & flags.colorDirty))
74 | locFlag |= flags.colorDirty;
75 |
76 | if(parentNode && parentNode._cascadeOpacityEnabled && (parentCmd._dirtyFlag & flags.opacityDirty))
77 | locFlag |= flags.opacityDirty;
78 |
79 | if(parentCmd && (parentCmd._dirtyFlag & flags.transformDirty))
80 | locFlag |= flags.transformDirty;
81 |
82 | var colorDirty = locFlag & flags.colorDirty,
83 | opacityDirty = locFlag & flags.opacityDirty;
84 |
85 | this._dirtyFlag = locFlag;
86 |
87 | if (colorDirty)
88 | this._syncDisplayColor();
89 | if (opacityDirty)
90 | this._syncDisplayOpacity();
91 |
92 | if(colorDirty || opacityDirty){
93 | this._setColorsString();
94 | this._updateColor();
95 | this._updateTexture();
96 | }else if(locFlag & flags.textDirty)
97 | this._updateTexture();
98 |
99 | this.transform(parentCmd);
100 | };
101 | })();
--------------------------------------------------------------------------------
/src/cocos2d/node-grid/CCNodeGrid.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | /**
28 | * NodeGrid class is a class serves as a decorator of cc.Node,
29 | * Grid node can run grid actions over all its children (WebGL only)
30 | *
31 | * @type {Class}
32 | *
33 | * @property {cc.GridBase} grid - Grid object that is used when applying effects
34 | * @property {cc.Node} target - <@writeonly>Target
35 | */
36 | cc.NodeGrid = cc.Node.extend({
37 | grid: null,
38 | _target: null,
39 |
40 | /**
41 | * Gets the grid object.
42 | * @returns {cc.GridBase}
43 | */
44 | getGrid: function () {
45 | return this.grid;
46 | },
47 |
48 | /**
49 | * Set the grid object.
50 | * @param {cc.GridBase} grid
51 | */
52 | setGrid: function (grid) {
53 | this.grid = grid;
54 | },
55 |
56 | /**
57 | * Set the target
58 | * @param {cc.Node} target
59 | */
60 | setTarget: function (target) {
61 | this._target = target;
62 | },
63 |
64 | _transformForWebGL: function () {
65 | //optimize performance for javascript
66 | var t4x4 = this._transform4x4, topMat4 = cc.current_stack.top;
67 |
68 | // Convert 3x3 into 4x4 matrix
69 | var trans = this.getNodeToParentTransform();
70 | var t4x4Mat = t4x4.mat;
71 | t4x4Mat[0] = trans.a;
72 | t4x4Mat[4] = trans.c;
73 | t4x4Mat[12] = trans.tx;
74 | t4x4Mat[1] = trans.b;
75 | t4x4Mat[5] = trans.d;
76 | t4x4Mat[13] = trans.ty;
77 |
78 | // Update Z vertex manually
79 | //this._transform4x4.mat[14] = this._vertexZ;
80 | t4x4Mat[14] = this._vertexZ;
81 |
82 | //optimize performance for Javascript
83 | topMat4.multiply(t4x4) ; // = cc.kmGLMultMatrix(this._transform4x4);
84 |
85 | // XXX: Expensive calls. Camera should be integrated into the cached affine matrix
86 | if (this._camera !== null && !(this.grid && this.grid.isActive())) {
87 | var app = this._renderCmd._anchorPointInPoints,
88 | apx = app.x, apy = app.y,
89 | translate = (apx !== 0.0 || apy !== 0.0);
90 | if (translate) {
91 | if(!cc.SPRITEBATCHNODE_RENDER_SUBPIXEL) {
92 | apx = 0 | apx;
93 | apy = 0 | apy;
94 | }
95 | cc.kmGLTranslatef(apx, apy, 0);
96 | this._camera.locate();
97 | cc.kmGLTranslatef(-apx, -apy, 0);
98 | } else {
99 | this._camera.locate();
100 | }
101 | }
102 | },
103 |
104 | _createRenderCmd: function(){
105 | if (cc._renderType === cc._RENDER_TYPE_WEBGL)
106 | return new cc.NodeGrid.WebGLRenderCmd(this);
107 | else
108 | return new cc.Node.CanvasRenderCmd(this); // cc.NodeGrid doesn't support Canvas mode.
109 | }
110 | });
111 |
112 | var _p = cc.NodeGrid.prototype;
113 | // Extended property
114 | /** @expose */
115 | _p.grid;
116 | /** @expose */
117 | _p.target;
118 | cc.defineGetterSetter(_p, "target", null, _p.setTarget);
119 |
120 |
121 | /**
122 | * Creates a NodeGrid.
123 | * Implementation cc.NodeGrid
124 | * @deprecated since v3.0 please new cc.NodeGrid instead.
125 | * @return {cc.NodeGrid}
126 | */
127 | cc.NodeGrid.create = function () {
128 | return new cc.NodeGrid();
129 | };
--------------------------------------------------------------------------------
/src/cocos2d/actions3d/CCActionPageTurn3D.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | /**
28 | *
29 | * This action simulates a page turn from the bottom right hand corner of the screen.
30 | * It's not much use by itself but is used by the PageTurnTransition.
31 | *
32 | * Based on an original paper by L Hong et al.
33 | * http://www.parc.com/publication/1638/turning-pages-of-3d-electronic-books.html
34 | *
35 | * @class
36 | * @extends cc.Grid3DAction
37 | */
38 | cc.PageTurn3D = cc.Grid3DAction.extend(/** @lends cc.PageTurn3D# */{
39 | /**
40 | * Update each tick
41 | * Time is the percentage of the way through the duration
42 | */
43 | update:function (time) {
44 | var tt = Math.max(0, time - 0.25);
45 | var deltaAy = (tt * tt * 500);
46 | var ay = -100 - deltaAy;
47 |
48 | var deltaTheta = -Math.PI / 2 * Math.sqrt(time);
49 | var theta = /*0.01f */ +Math.PI / 2 + deltaTheta;
50 |
51 | var sinTheta = Math.sin(theta);
52 | var cosTheta = Math.cos(theta);
53 |
54 | var locGridSize = this._gridSize;
55 | var locVer = cc.p(0, 0);
56 | for (var i = 0; i <= locGridSize.width; ++i) {
57 | for (var j = 0; j <= locGridSize.height; ++j) {
58 | locVer.x = i;
59 | locVer.y = j;
60 | // Get original vertex
61 | var p = this.originalVertex(locVer);
62 |
63 | var R = Math.sqrt((p.x * p.x) + ((p.y - ay) * (p.y - ay)));
64 | var r = R * sinTheta;
65 | var alpha = Math.asin(p.x / R);
66 | var beta = alpha / sinTheta;
67 | var cosBeta = Math.cos(beta);
68 |
69 | // If beta > PI then we've wrapped around the cone
70 | // Reduce the radius to stop these points interfering with others
71 | if (beta <= Math.PI)
72 | p.x = ( r * Math.sin(beta));
73 | else
74 | p.x = 0; //Force X = 0 to stop wrapped points
75 |
76 | p.y = ( R + ay - ( r * (1 - cosBeta) * sinTheta));
77 |
78 | // We scale z here to avoid the animation being
79 | // too much bigger than the screen due to perspectve transform
80 | p.z = (r * ( 1 - cosBeta ) * cosTheta) / 7;// "100" didn't work for
81 |
82 | // Stop z coord from dropping beneath underlying page in a transition
83 | // issue #751
84 | if (p.z < 0.5)
85 | p.z = 0.5;
86 |
87 | // Set new coords
88 | this.setVertex(locVer, p);
89 | }
90 | }
91 | }
92 | });
93 |
94 | /**
95 | * create PageTurn3D action
96 | * @function
97 | * @param {Number} duration
98 | * @param {cc.Size} gridSize
99 | * @return {cc.PageTurn3D}
100 | */
101 | cc.pageTurn3D = function (duration, gridSize) {
102 | return new cc.PageTurn3D(duration, gridSize);
103 | };
104 | /**
105 | * Please use cc.pageTurn3D instead
106 | * create PageTurn3D action
107 | * @param {Number} duration
108 | * @param {cc.Size} gridSize
109 | * @return {cc.PageTurn3D}
110 | * @static
111 | * @deprecated since v3.0 please use cc.pageTurn3D instead.
112 | */
113 | cc.PageTurn3D.create = cc.pageTurn3D;
--------------------------------------------------------------------------------
/src/cocos2d/core/platform/CCInputExtension.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | var _p = cc.inputManager;
27 |
28 | /**
29 | * whether enable accelerometer event
30 | * @function
31 | * @param {Boolean} isEnable
32 | */
33 | _p.setAccelerometerEnabled = function(isEnable){
34 | var _t = this;
35 | if(_t._accelEnabled === isEnable)
36 | return;
37 |
38 | _t._accelEnabled = isEnable;
39 | var scheduler = cc.director.getScheduler();
40 | if(_t._accelEnabled){
41 | _t._accelCurTime = 0;
42 | scheduler.scheduleUpdate(_t);
43 | } else {
44 | _t._accelCurTime = 0;
45 | scheduler.scheduleUpdate(_t);
46 | }
47 | };
48 |
49 | /**
50 | * set accelerometer interval value
51 | * @function
52 | * @param {Number} interval
53 | */
54 | _p.setAccelerometerInterval = function(interval){
55 | if (this._accelInterval !== interval) {
56 | this._accelInterval = interval;
57 | }
58 | };
59 |
60 | _p._registerKeyboardEvent = function(){
61 | cc._addEventListener(cc._canvas, "keydown", function (e) {
62 | cc.eventManager.dispatchEvent(new cc.EventKeyboard(e.keyCode, true));
63 | e.stopPropagation();
64 | e.preventDefault();
65 | }, false);
66 | cc._addEventListener(cc._canvas, "keyup", function (e) {
67 | cc.eventManager.dispatchEvent(new cc.EventKeyboard(e.keyCode, false));
68 | e.stopPropagation();
69 | e.preventDefault();
70 | }, false);
71 | };
72 |
73 | _p._registerAccelerometerEvent = function(){
74 | var w = window, _t = this;
75 | _t._acceleration = new cc.Acceleration();
76 | _t._accelDeviceEvent = w.DeviceMotionEvent || w.DeviceOrientationEvent;
77 |
78 | //TODO fix DeviceMotionEvent bug on QQ Browser version 4.1 and below.
79 | if (cc.sys.browserType === cc.sys.BROWSER_TYPE_MOBILE_QQ)
80 | _t._accelDeviceEvent = window.DeviceOrientationEvent;
81 |
82 | var _deviceEventType = (_t._accelDeviceEvent === w.DeviceMotionEvent) ? "devicemotion" : "deviceorientation";
83 | var ua = navigator.userAgent;
84 | if (/Android/.test(ua) || (/Adr/.test(ua) && cc.sys.browserType === cc.BROWSER_TYPE_UC)) {
85 | _t._minus = -1;
86 | }
87 |
88 | cc._addEventListener(w, _deviceEventType, _t.didAccelerate.bind(_t), false);
89 | };
90 |
91 | _p.didAccelerate = function (eventData) {
92 | var _t = this, w = window;
93 | if (!_t._accelEnabled)
94 | return;
95 |
96 | var mAcceleration = _t._acceleration;
97 |
98 | var x, y, z;
99 |
100 | if (_t._accelDeviceEvent === window.DeviceMotionEvent) {
101 | var eventAcceleration = eventData["accelerationIncludingGravity"];
102 | x = _t._accelMinus * eventAcceleration.x * 0.1;
103 | y = _t._accelMinus * eventAcceleration.y * 0.1;
104 | z = eventAcceleration.z * 0.1;
105 | } else {
106 | x = (eventData["gamma"] / 90) * 0.981;
107 | y = -(eventData["beta"] / 90) * 0.981;
108 | z = (eventData["alpha"] / 90) * 0.981;
109 | }
110 |
111 | if(cc.sys.os === cc.sys.OS_ANDROID){
112 | mAcceleration.x = -x;
113 | mAcceleration.y = -y;
114 | }else{
115 | mAcceleration.x = x;
116 | mAcceleration.y = y;
117 | }
118 | mAcceleration.z = z;
119 |
120 | mAcceleration.timestamp = eventData.timeStamp || Date.now();
121 |
122 | var tmpX = mAcceleration.x;
123 | if(w.orientation === cc.UIInterfaceOrientationLandscapeRight){
124 | mAcceleration.x = -mAcceleration.y;
125 | mAcceleration.y = tmpX;
126 | }else if(w.orientation === cc.UIInterfaceOrientationLandscapeLeft){
127 | mAcceleration.x = mAcceleration.y;
128 | mAcceleration.y = -tmpX;
129 | }else if(w.orientation === cc.UIInterfaceOrientationPortraitUpsideDown){
130 | mAcceleration.x = -mAcceleration.x;
131 | mAcceleration.y = -mAcceleration.y;
132 | }
133 | };
134 |
135 | delete _p;
--------------------------------------------------------------------------------
/src/cocos2d/kazmath/plane.js:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2008, Luke Benstead.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification,
9 | are permitted provided that the following conditions are met:
10 |
11 | Redistributions of source code must retain the above copyright notice,
12 | this list of conditions and the following disclaimer.
13 | Redistributions in binary form must reproduce the above copyright notice,
14 | this list of conditions and the following disclaimer in the documentation
15 | and/or other materials provided with the distribution.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | /**
30 | * @ignore
31 | */
32 | (function(cc){
33 | cc.math.Plane = function (a, b, c, d) {
34 | if (a && b === undefined) {
35 | this.a = a.a;
36 | this.b = a.b;
37 | this.c = a.c;
38 | this.d = a.d;
39 | } else {
40 | this.a = a || 0;
41 | this.b = b || 0;
42 | this.c = c || 0;
43 | this.d = d || 0;
44 | }
45 | };
46 | cc.kmPlane = cc.math.Plane;
47 | var proto = cc.math.Plane.prototype;
48 |
49 | cc.math.Plane.LEFT = 0;
50 |
51 | cc.math.Plane.RIGHT = 1;
52 |
53 | cc.math.Plane.BOTTOM = 2;
54 |
55 | cc.math.Plane.TOP = 3;
56 |
57 | cc.math.Plane.NEAR = 4;
58 |
59 | cc.math.Plane.FAR = 5;
60 |
61 | cc.math.Plane.POINT_INFRONT_OF_PLANE = 0;
62 |
63 | cc.math.Plane.POINT_BEHIND_PLANE = 1;
64 |
65 | cc.math.Plane.POINT_ON_PLANE = 2;
66 |
67 | proto.dot = function(vec4){ //cc.kmPlaneDot
68 | return (this.a * vec4.x + this.b * vec4.y + this.c * vec4.z + this.d * vec4.w);
69 | };
70 |
71 | proto.dotCoord = function(vec3) { //=cc.kmPlaneDotCoord
72 | return (this.a * vec3.x + this.b * vec3.y + this.c * vec3.z + this.d);
73 | };
74 |
75 | proto.dotNormal = function(vec3) { //=cc.kmPlaneDotNormal
76 | return (this.a * vec3.x + this.b * vec3.y + this.c * vec3.z);
77 | };
78 |
79 | cc.math.Plane.fromPointNormal = function(vec3, normal) { //cc.kmPlaneFromPointNormal
80 | /*
81 | Planea = Nx
82 | Planeb = Ny
83 | Planec = Nz
84 | Planed = −N⋅P
85 | */
86 | return new cc.math.Plane(normal.x, normal.y, normal.z, -normal.dot(vec3));
87 | };
88 |
89 | cc.math.Plane.fromPoints = function(vec1, vec2, vec3) { //cc.kmPlaneFromPoints
90 | /*
91 | v = (B − A) × (C − A)
92 | n = 1⁄|v| v
93 | Outa = nx
94 | Outb = ny
95 | Outc = nz
96 | Outd = −n⋅A
97 | */
98 | var v1 = new cc.math.Vec3(vec2), v2 = new cc.math.Vec3(vec3), plane = new cc.math.Plane();
99 | v1.subtract(vec1); //Create the vectors for the 2 sides of the triangle
100 | v2.subtract(vec1);
101 | v1.cross(v2); // Use the cross product to get the normal
102 | v1.normalize(); //Normalize it and assign to pOut.m_N
103 |
104 | plane.a = v1.x;
105 | plane.b = v1.y;
106 | plane.c = v1.z;
107 | plane.d = v1.scale(-1.0).dot(vec1);
108 | return plane;
109 | };
110 |
111 | proto.normalize = function(){ //cc.kmPlaneNormalize
112 | var n = new cc.math.Vec3(this.a, this.b, this.c), l = 1.0 / n.length(); //Get 1/length
113 | n.normalize(); //Normalize the vector and assign to pOut
114 | this.a = n.x;
115 | this.b = n.y;
116 | this.c = n.z;
117 | this.d = this.d * l; //Scale the D value and assign to pOut
118 | return this;
119 | };
120 |
121 | proto.classifyPoint = function(vec3) {
122 | // This function will determine if a point is on, in front of, or behind
123 | // the plane. First we store the dot product of the plane and the point.
124 | var distance = this.a * vec3.x + this.b * vec3.y + this.c * vec3.z + this.d;
125 |
126 | // Simply put if the dot product is greater than 0 then it is infront of it.
127 | // If it is less than 0 then it is behind it. And if it is 0 then it is on it.
128 | if(distance > 0.001)
129 | return cc.math.Plane.POINT_INFRONT_OF_PLANE;
130 | if(distance < -0.001)
131 | return cc.math.Plane.POINT_BEHIND_PLANE;
132 | return cc.math.Plane.POINT_ON_PLANE;
133 | };
134 | })(cc);
135 |
136 |
137 |
138 |
--------------------------------------------------------------------------------
/src/cocos2d/core/base-nodes/BaseNodesPropertyDefine.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | cc._tmp.PrototypeCCNode = function () {
28 |
29 | var _p = cc.Node.prototype;
30 |
31 | cc.defineGetterSetter(_p, "x", _p.getPositionX, _p.setPositionX);
32 | cc.defineGetterSetter(_p, "y", _p.getPositionY, _p.setPositionY);
33 | /** @expose */
34 | _p.width;
35 | cc.defineGetterSetter(_p, "width", _p._getWidth, _p._setWidth);
36 | /** @expose */
37 | _p.height;
38 | cc.defineGetterSetter(_p, "height", _p._getHeight, _p._setHeight);
39 | /** @expose */
40 | _p.anchorX;
41 | cc.defineGetterSetter(_p, "anchorX", _p._getAnchorX, _p._setAnchorX);
42 | /** @expose */
43 | _p.anchorY;
44 | cc.defineGetterSetter(_p, "anchorY", _p._getAnchorY, _p._setAnchorY);
45 | /** @expose */
46 | _p.skewX;
47 | cc.defineGetterSetter(_p, "skewX", _p.getSkewX, _p.setSkewX);
48 | /** @expose */
49 | _p.skewY;
50 | cc.defineGetterSetter(_p, "skewY", _p.getSkewY, _p.setSkewY);
51 | /** @expose */
52 | _p.zIndex;
53 | cc.defineGetterSetter(_p, "zIndex", _p.getLocalZOrder, _p.setLocalZOrder);
54 | /** @expose */
55 | _p.vertexZ;
56 | cc.defineGetterSetter(_p, "vertexZ", _p.getVertexZ, _p.setVertexZ);
57 | /** @expose */
58 | _p.rotation;
59 | cc.defineGetterSetter(_p, "rotation", _p.getRotation, _p.setRotation);
60 | /** @expose */
61 | _p.rotationX;
62 | cc.defineGetterSetter(_p, "rotationX", _p.getRotationX, _p.setRotationX);
63 | /** @expose */
64 | _p.rotationY;
65 | cc.defineGetterSetter(_p, "rotationY", _p.getRotationY, _p.setRotationY);
66 | /** @expose */
67 | _p.scale;
68 | cc.defineGetterSetter(_p, "scale", _p.getScale, _p.setScale);
69 | /** @expose */
70 | _p.scaleX;
71 | cc.defineGetterSetter(_p, "scaleX", _p.getScaleX, _p.setScaleX);
72 | /** @expose */
73 | _p.scaleY;
74 | cc.defineGetterSetter(_p, "scaleY", _p.getScaleY, _p.setScaleY);
75 | /** @expose */
76 | _p.children;
77 | cc.defineGetterSetter(_p, "children", _p.getChildren);
78 | /** @expose */
79 | _p.childrenCount;
80 | cc.defineGetterSetter(_p, "childrenCount", _p.getChildrenCount);
81 | /** @expose */
82 | _p.parent;
83 | cc.defineGetterSetter(_p, "parent", _p.getParent, _p.setParent);
84 | /** @expose */
85 | _p.visible;
86 | cc.defineGetterSetter(_p, "visible", _p.isVisible, _p.setVisible);
87 | /** @expose */
88 | _p.running;
89 | cc.defineGetterSetter(_p, "running", _p.isRunning);
90 | /** @expose */
91 | _p.ignoreAnchor;
92 | cc.defineGetterSetter(_p, "ignoreAnchor", _p.isIgnoreAnchorPointForPosition, _p.ignoreAnchorPointForPosition);
93 | /** @expose */
94 | _p.tag;
95 | /** @expose */
96 | _p.userData;
97 | /** @expose */
98 | _p.userObject;
99 | /** @expose */
100 | _p.arrivalOrder;
101 | /** @expose */
102 | _p.actionManager;
103 | cc.defineGetterSetter(_p, "actionManager", _p.getActionManager, _p.setActionManager);
104 | /** @expose */
105 | _p.scheduler;
106 | cc.defineGetterSetter(_p, "scheduler", _p.getScheduler, _p.setScheduler);
107 | //cc.defineGetterSetter(_p, "boundingBox", _p.getBoundingBox);
108 | /** @expose */
109 | _p.shaderProgram;
110 | cc.defineGetterSetter(_p, "shaderProgram", _p.getShaderProgram, _p.setShaderProgram);
111 |
112 | /** @expose */
113 | _p.opacity;
114 | cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity);
115 | /** @expose */
116 | _p.opacityModifyRGB;
117 | cc.defineGetterSetter(_p, "opacityModifyRGB", _p.isOpacityModifyRGB);
118 | /** @expose */
119 | _p.cascadeOpacity;
120 | cc.defineGetterSetter(_p, "cascadeOpacity", _p.isCascadeOpacityEnabled, _p.setCascadeOpacityEnabled);
121 | /** @expose */
122 | _p.color;
123 | cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor);
124 | /** @expose */
125 | _p.cascadeColor;
126 | cc.defineGetterSetter(_p, "cascadeColor", _p.isCascadeColorEnabled, _p.setCascadeColorEnabled);
127 | };
--------------------------------------------------------------------------------
/src/cocos2d/core/platform/CCTypesPropertyDefine.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | cc._tmp.PrototypeColor = function () {
28 | var _p = cc.color;
29 | /**
30 | * White color (255, 255, 255, 255)
31 | * @returns {cc.Color}
32 | * @private
33 | */
34 | _p._getWhite = function () {
35 | return _p(255, 255, 255);
36 | };
37 |
38 | /**
39 | * Yellow color (255, 255, 0, 255)
40 | * @returns {cc.Color}
41 | * @private
42 | */
43 | _p._getYellow = function () {
44 | return _p(255, 255, 0);
45 | };
46 |
47 | /**
48 | * Blue color (0, 0, 255, 255)
49 | * @type {cc.Color}
50 | * @private
51 | */
52 | _p._getBlue = function () {
53 | return _p(0, 0, 255);
54 | };
55 |
56 | /**
57 | * Green Color (0, 255, 0, 255)
58 | * @type {cc.Color}
59 | * @private
60 | */
61 | _p._getGreen = function () {
62 | return _p(0, 255, 0);
63 | };
64 |
65 | /**
66 | * Red Color (255, 0, 0, 255)
67 | * @type {cc.Color}
68 | * @private
69 | */
70 | _p._getRed = function () {
71 | return _p(255, 0, 0);
72 | };
73 |
74 | /**
75 | * Magenta Color (255, 0, 255, 255)
76 | * @type {cc.Color}
77 | * @private
78 | */
79 | _p._getMagenta = function () {
80 | return _p(255, 0, 255);
81 | };
82 |
83 | /**
84 | * Black Color (0, 0, 0, 255)
85 | * @type {cc.Color}
86 | * @private
87 | */
88 | _p._getBlack = function () {
89 | return _p(0, 0, 0);
90 | };
91 |
92 | /**
93 | * Orange Color (255, 127, 0, 255)
94 | * @type {_p}
95 | * @private
96 | */
97 | _p._getOrange = function () {
98 | return _p(255, 127, 0);
99 | };
100 |
101 | /**
102 | * Gray Color (166, 166, 166, 255)
103 | * @type {_p}
104 | * @private
105 | */
106 | _p._getGray = function () {
107 | return _p(166, 166, 166);
108 | };
109 |
110 | /** @expose */
111 | _p.WHITE;
112 | cc.defineGetterSetter(_p, "WHITE", _p._getWhite);
113 | /** @expose */
114 | _p.YELLOW;
115 | cc.defineGetterSetter(_p, "YELLOW", _p._getYellow);
116 | /** @expose */
117 | _p.BLUE;
118 | cc.defineGetterSetter(_p, "BLUE", _p._getBlue);
119 | /** @expose */
120 | _p.GREEN;
121 | cc.defineGetterSetter(_p, "GREEN", _p._getGreen);
122 | /** @expose */
123 | _p.RED;
124 | cc.defineGetterSetter(_p, "RED", _p._getRed);
125 | /** @expose */
126 | _p.MAGENTA;
127 | cc.defineGetterSetter(_p, "MAGENTA", _p._getMagenta);
128 | /** @expose */
129 | _p.BLACK;
130 | cc.defineGetterSetter(_p, "BLACK", _p._getBlack);
131 | /** @expose */
132 | _p.ORANGE;
133 | cc.defineGetterSetter(_p, "ORANGE", _p._getOrange);
134 | /** @expose */
135 | _p.GRAY;
136 | cc.defineGetterSetter(_p, "GRAY", _p._getGray);
137 |
138 | cc.BlendFunc._disable = function(){
139 | return new cc.BlendFunc(cc.ONE, cc.ZERO);
140 | };
141 | cc.BlendFunc._alphaPremultiplied = function(){
142 | return new cc.BlendFunc(cc.ONE, cc.ONE_MINUS_SRC_ALPHA);
143 | };
144 | cc.BlendFunc._alphaNonPremultiplied = function(){
145 | return new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE_MINUS_SRC_ALPHA);
146 | };
147 | cc.BlendFunc._additive = function(){
148 | return new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE);
149 | };
150 |
151 | /** @expose */
152 | cc.BlendFunc.DISABLE;
153 | cc.defineGetterSetter(cc.BlendFunc, "DISABLE", cc.BlendFunc._disable);
154 | /** @expose */
155 | cc.BlendFunc.ALPHA_PREMULTIPLIED;
156 | cc.defineGetterSetter(cc.BlendFunc, "ALPHA_PREMULTIPLIED", cc.BlendFunc._alphaPremultiplied);
157 | /** @expose */
158 | cc.BlendFunc.ALPHA_NON_PREMULTIPLIED;
159 | cc.defineGetterSetter(cc.BlendFunc, "ALPHA_NON_PREMULTIPLIED", cc.BlendFunc._alphaNonPremultiplied);
160 | /** @expose */
161 | cc.BlendFunc.ADDITIVE;
162 | cc.defineGetterSetter(cc.BlendFunc, "ADDITIVE", cc.BlendFunc._additive);
163 | };
164 |
165 |
166 |
--------------------------------------------------------------------------------
/src/cocos2d/core/platform/CCLoaders.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | cc._txtLoader = {
27 | load : function(realUrl, url, res, cb){
28 | cc.loader.loadTxt(realUrl, cb);
29 | }
30 | };
31 | cc.loader.register(["txt", "xml", "vsh", "fsh", "atlas"], cc._txtLoader);
32 |
33 | cc._jsonLoader = {
34 | load : function(realUrl, url, res, cb){
35 | cc.loader.loadJson(realUrl, cb);
36 | }
37 | };
38 | cc.loader.register(["json", "ExportJson"], cc._jsonLoader);
39 |
40 | cc._jsLoader = {
41 | load : function(realUrl, url, res, cb){
42 | cc.loader.loadJs(realUrl, cb);
43 | }
44 | };
45 | cc.loader.register(["js"], cc._jsLoader);
46 |
47 | cc._imgLoader = {
48 | load : function(realUrl, url, res, cb){
49 | cc.loader.cache[url] = cc.loader.loadImg(realUrl, function(err, img){
50 | if(err)
51 | return cb(err);
52 | cc.textureCache.handleLoadedTexture(url);
53 | cb(null, img);
54 | });
55 | }
56 | };
57 | cc.loader.register(["png", "jpg", "bmp","jpeg","gif", "ico"], cc._imgLoader);
58 | cc._serverImgLoader = {
59 | load : function(realUrl, url, res, cb){
60 | cc.loader.cache[url] = cc.loader.loadImg(res.src, function(err, img){
61 | if(err)
62 | return cb(err);
63 | cc.textureCache.handleLoadedTexture(url);
64 | cb(null, img);
65 | });
66 | }
67 | };
68 | cc.loader.register(["serverImg"], cc._serverImgLoader);
69 |
70 | cc._plistLoader = {
71 | load : function(realUrl, url, res, cb){
72 | cc.loader.loadTxt(realUrl, function(err, txt){
73 | if(err)
74 | return cb(err);
75 | cb(null, cc.plistParser.parse(txt));
76 | });
77 | }
78 | };
79 | cc.loader.register(["plist"], cc._plistLoader);
80 |
81 | cc._fontLoader = {
82 | TYPE : {
83 | ".eot" : "embedded-opentype",
84 | ".ttf" : "truetype",
85 | ".woff" : "woff",
86 | ".svg" : "svg"
87 | },
88 | _loadFont : function(name, srcs, type){
89 | var doc = document, path = cc.path, TYPE = this.TYPE, fontStyle = cc.newElement("style");
90 | fontStyle.type = "text/css";
91 | doc.body.appendChild(fontStyle);
92 |
93 | var fontStr = "@font-face { font-family:" + name + "; src:";
94 | if(srcs instanceof Array){
95 | for(var i = 0, li = srcs.length; i < li; i++){
96 | var src = srcs[i];
97 | type = path.extname(src).toLowerCase();
98 | fontStr += "url('" + srcs[i] + "') format('" + TYPE[type] + "')";
99 | fontStr += (i === li - 1) ? ";" : ",";
100 | }
101 | }else{
102 | fontStr += "url('" + srcs + "') format('" + TYPE[type] + "');";
103 | }
104 | fontStyle.textContent += fontStr + "};";
105 |
106 | //.
107 | var preloadDiv = cc.newElement("div");
108 | var _divStyle = preloadDiv.style;
109 | _divStyle.fontFamily = name;
110 | preloadDiv.innerHTML = ".";
111 | _divStyle.position = "absolute";
112 | _divStyle.left = "-100px";
113 | _divStyle.top = "-100px";
114 | doc.body.appendChild(preloadDiv);
115 | },
116 | load : function(realUrl, url, res, cb){
117 | var self = this;
118 | var type = res.type, name = res.name, srcs = res.srcs;
119 | if(cc.isString(res)){
120 | type = cc.path.extname(res);
121 | name = cc.path.basename(res, type);
122 | self._loadFont(name, res, type);
123 | }else{
124 | self._loadFont(name, srcs);
125 | }
126 | cb(null, true);
127 | }
128 | };
129 | cc.loader.register(["font", "eot", "ttf", "woff", "svg"], cc._fontLoader);
130 |
131 | cc._binaryLoader = {
132 | load : function(realUrl, url, res, cb){
133 | cc.loader.loadBinary(realUrl, cb);
134 | }
135 | };
136 |
137 | cc._csbLoader = {
138 | load: function(realUrl, url, res, cb){
139 | cc.loader.loadCsb(realUrl, cb);
140 | }
141 | };
142 | cc.loader.register(["csb"], cc._csbLoader);
--------------------------------------------------------------------------------
/src/cocos2d/tilemap/CCTMXObjectGroup.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | /**
28 | * cc.TMXObjectGroup represents the TMX object group.
29 | * @class
30 | * @extends cc.Class
31 | *
32 | * @property {Array} properties - Properties from the group. They can be added using tilemap editors
33 | * @property {String} groupName - Name of the group
34 | */
35 | cc.TMXObjectGroup = cc.Class.extend(/** @lends cc.TMXObjectGroup# */{
36 | properties: null,
37 | groupName: "",
38 |
39 | _positionOffset: null,
40 | _objects: null,
41 |
42 | /**
43 | * The cc.TMXObjectGroup's constructor.
44 | * This function will automatically be invoked when you create a node using new construction: "var node = new cc.TMXObjectGroup()".
45 | * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.
46 | */
47 | ctor:function () {
48 | this.groupName = "";
49 | this._positionOffset = cc.p(0,0);
50 | this.properties = [];
51 | this._objects = [];
52 | },
53 |
54 | /**
55 | * Offset position of child objects
56 | * @return {cc.Point}
57 | */
58 | getPositionOffset:function () {
59 | return cc.p(this._positionOffset);
60 | },
61 |
62 | /**
63 | * Offset position of child objects
64 | * @param {cc.Point} offset
65 | */
66 | setPositionOffset:function (offset) {
67 | this._positionOffset.x = offset.x;
68 | this._positionOffset.y = offset.y;
69 | },
70 |
71 | /**
72 | * List of properties stored in a dictionary
73 | * @return {Array}
74 | */
75 | getProperties:function () {
76 | return this.properties;
77 | },
78 |
79 | /**
80 | * List of properties stored in a dictionary
81 | * @param {object} Var
82 | */
83 | setProperties:function (Var) {
84 | this.properties.push(Var);
85 | },
86 |
87 | /**
88 | * Gets the Group name.
89 | * @return {String}
90 | */
91 | getGroupName:function () {
92 | return this.groupName.toString();
93 | },
94 |
95 | /**
96 | * Set the Group name
97 | * @param {String} groupName
98 | */
99 | setGroupName:function (groupName) {
100 | this.groupName = groupName;
101 | },
102 |
103 | /**
104 | * Return the value for the specific property name
105 | * @param {String} propertyName
106 | * @return {object}
107 | */
108 | propertyNamed:function (propertyName) {
109 | return this.properties[propertyName];
110 | },
111 |
112 | /**
113 | * Return the dictionary for the specific object name.
114 | * It will return the 1st object found on the array for the given name.
115 | * @deprecated since v3.4 please use .getObject
116 | * @param {String} objectName
117 | * @return {object|Null}
118 | */
119 | objectNamed:function (objectName) {
120 | this.getObject(objectName);
121 | },
122 |
123 | /**
124 | * Return the dictionary for the specific object name.
125 | * It will return the 1st object found on the array for the given name.
126 | * @param {String} objectName
127 | * @return {object|Null}
128 | */
129 | getObject: function(objectName){
130 | if (this._objects && this._objects.length > 0) {
131 | var locObjects = this._objects;
132 | for (var i = 0, len = locObjects.length; i < len; i++) {
133 | var name = locObjects[i]["name"];
134 | if (name && name === objectName)
135 | return locObjects[i];
136 | }
137 | }
138 | // object not found
139 | return null;
140 | },
141 |
142 | /**
143 | * Gets the objects.
144 | * @return {Array}
145 | */
146 | getObjects:function () {
147 | return this._objects;
148 | },
149 |
150 | /**
151 | * Set the objects.
152 | * @param {object} objects
153 | */
154 | setObjects:function (objects) {
155 | this._objects.push(objects);
156 | }
157 | });
158 |
--------------------------------------------------------------------------------
/src/cocos2d/core/renderer/RendererWebGL.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2013-2014 Chukong Technologies Inc.
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | cc.rendererWebGL = {
26 | childrenOrderDirty: true,
27 | _transformNodePool: [], //save nodes transform dirty
28 | _renderCmds: [], //save renderer commands
29 |
30 | _isCacheToBufferOn: false, //a switch that whether cache the rendererCmd to cacheToCanvasCmds
31 | _cacheToBufferCmds: {}, // an array saves the renderer commands need for cache to other canvas
32 | _cacheInstanceIds: [],
33 | _currentID: 0,
34 |
35 | getRenderCmd: function (renderableObject) {
36 | //TODO Add renderCmd pool here
37 | return renderableObject._createRenderCmd();
38 | },
39 |
40 | /**
41 | * drawing all renderer command to context (default is cc._renderContext)
42 | * @param {WebGLRenderingContext} [ctx=cc._renderContext]
43 | */
44 | rendering: function (ctx) {
45 | var locCmds = this._renderCmds,
46 | i,
47 | len;
48 | var context = ctx || cc._renderContext;
49 | for (i = 0, len = locCmds.length; i < len; i++) {
50 | locCmds[i].rendering(context);
51 | }
52 | },
53 |
54 | _turnToCacheMode: function (renderTextureID) {
55 | this._isCacheToBufferOn = true;
56 | renderTextureID = renderTextureID || 0;
57 | this._cacheToBufferCmds[renderTextureID] = [];
58 | this._cacheInstanceIds.push(renderTextureID);
59 | this._currentID = renderTextureID;
60 | },
61 |
62 | _turnToNormalMode: function () {
63 | this._isCacheToBufferOn = false;
64 | },
65 |
66 | /**
67 | * drawing all renderer command to cache canvas' context
68 | * @param {Number} [renderTextureId]
69 | */
70 | _renderingToBuffer: function (renderTextureId) {
71 | renderTextureId = renderTextureId || this._currentID;
72 | var locCmds = this._cacheToBufferCmds[renderTextureId], i, len;
73 | var ctx = cc._renderContext, locIDs = this._cacheInstanceIds;
74 | for (i = 0, len = locCmds.length; i < len; i++) {
75 | locCmds[i].rendering(ctx);
76 | }
77 | locCmds.length = 0;
78 | delete this._cacheToBufferCmds[renderTextureId];
79 | cc.arrayRemoveObject(locIDs, renderTextureId);
80 |
81 | if (locIDs.length === 0)
82 | this._isCacheToBufferOn = false;
83 | else
84 | this._currentID = locIDs[locIDs.length - 1];
85 | },
86 |
87 | //reset renderer's flag
88 | resetFlag: function () {
89 | this.childrenOrderDirty = false;
90 | this._transformNodePool.length = 0;
91 | },
92 |
93 | //update the transform data
94 | transform: function () {
95 | var locPool = this._transformNodePool;
96 | //sort the pool
97 | locPool.sort(this._sortNodeByLevelAsc);
98 | //transform node
99 | for (var i = 0, len = locPool.length; i < len; i++) {
100 | locPool[i].updateStatus();
101 | }
102 | locPool.length = 0;
103 | },
104 |
105 | transformDirty: function () {
106 | return this._transformNodePool.length > 0;
107 | },
108 |
109 | _sortNodeByLevelAsc: function (n1, n2) {
110 | return n1._curLevel - n2._curLevel;
111 | },
112 |
113 | pushDirtyNode: function (node) {
114 | //if (this._transformNodePool.indexOf(node) === -1)
115 | this._transformNodePool.push(node);
116 | },
117 |
118 | clearRenderCommands: function () {
119 | this._renderCmds.length = 0;
120 | },
121 |
122 | pushRenderCommand: function (cmd) {
123 | if(!cmd._needDraw)
124 | return;
125 | if (this._isCacheToBufferOn) {
126 | var currentId = this._currentID, locCmdBuffer = this._cacheToBufferCmds;
127 | var cmdList = locCmdBuffer[currentId];
128 | if (cmdList.indexOf(cmd) === -1)
129 | cmdList.push(cmd);
130 | } else {
131 | if (this._renderCmds.indexOf(cmd) === -1)
132 | this._renderCmds.push(cmd);
133 | }
134 | }
135 | };
136 | if (cc._renderType === cc._RENDER_TYPE_WEBGL)
137 | cc.renderer = cc.rendererWebGL;
138 |
--------------------------------------------------------------------------------
/src/cocos2d/core/event-manager/CCTouch.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 |
26 | /**
27 | * The touch event class
28 | * @class
29 | * @extends cc.Class
30 | *
31 | * @param {Number} x
32 | * @param {Number} y
33 | * @param {Number} id
34 | */
35 | cc.Touch = cc.Class.extend(/** @lends cc.Touch# */{
36 | _point:null,
37 | _prevPoint:null,
38 | _id:0,
39 | _startPointCaptured: false,
40 | _startPoint:null,
41 |
42 | ctor:function (x, y, id) {
43 | this._point = cc.p(x || 0, y || 0);
44 | this._id = id || 0;
45 | },
46 |
47 | /**
48 | * Returns the current touch location in OpenGL coordinates
49 | * @return {cc.Point}
50 | */
51 | getLocation:function () {
52 | //TODO
53 | //return cc.director.convertToGL(this._point);
54 | return {x: this._point.x, y: this._point.y};
55 | },
56 |
57 | /**
58 | * Returns X axis location value
59 | * @returns {number}
60 | */
61 | getLocationX: function () {
62 | return this._point.x;
63 | },
64 |
65 | /**
66 | * Returns Y axis location value
67 | * @returns {number}
68 | */
69 | getLocationY: function () {
70 | return this._point.y;
71 | },
72 |
73 | /**
74 | * Returns the previous touch location in OpenGL coordinates
75 | * @return {cc.Point}
76 | */
77 | getPreviousLocation:function () {
78 | //TODO
79 | //return cc.director.convertToGL(this._prevPoint);
80 | return {x: this._prevPoint.x, y: this._prevPoint.y};
81 | },
82 |
83 | /**
84 | * Returns the start touch location in OpenGL coordinates
85 | * @returns {cc.Point}
86 | */
87 | getStartLocation: function() {
88 | //TODO
89 | //return cc.director.convertToGL(this._startPoint);
90 | return {x: this._startPoint.x, y: this._startPoint.y};
91 | },
92 |
93 | /**
94 | * Returns the delta distance from the previous touche to the current one in screen coordinates
95 | * @return {cc.Point}
96 | */
97 | getDelta:function () {
98 | return cc.pSub(this._point, this._prevPoint);
99 | },
100 |
101 | /**
102 | * Returns the current touch location in screen coordinates
103 | * @return {cc.Point}
104 | */
105 | getLocationInView: function() {
106 | return {x: this._point.x, y: this._point.y};
107 | },
108 |
109 | /**
110 | * Returns the previous touch location in screen coordinates
111 | * @return {cc.Point}
112 | */
113 | getPreviousLocationInView: function(){
114 | return {x: this._prevPoint.x, y: this._prevPoint.y};
115 | },
116 |
117 | /**
118 | * Returns the start touch location in screen coordinates
119 | * @return {cc.Point}
120 | */
121 | getStartLocationInView: function(){
122 | return {x: this._startPoint.x, y: this._startPoint.y};
123 | },
124 |
125 | /**
126 | * Returns the id of cc.Touch
127 | * @return {Number}
128 | */
129 | getID:function () {
130 | return this._id;
131 | },
132 |
133 | /**
134 | * Returns the id of cc.Touch
135 | * @return {Number}
136 | * @deprecated since v3.0, please use getID() instead
137 | */
138 | getId:function () {
139 | cc.log("getId is deprecated. Please use getID instead.")
140 | return this._id;
141 | },
142 |
143 | /**
144 | * Sets information to touch
145 | * @param {Number} id
146 | * @param {Number} x
147 | * @param {Number} y
148 | */
149 | setTouchInfo:function (id, x, y) {
150 | this._prevPoint = this._point;
151 | this._point = cc.p(x || 0, y || 0);
152 | this._id = id;
153 | if(!this._startPointCaptured){
154 | this._startPoint = cc.p(this._point);
155 | this._startPointCaptured = true;
156 | }
157 | },
158 |
159 | _setPoint: function(x, y){
160 | if(y === undefined){
161 | this._point.x = x.x;
162 | this._point.y = x.y;
163 | }else{
164 | this._point.x = x;
165 | this._point.y = y;
166 | }
167 | },
168 |
169 | _setPrevPoint:function (x, y) {
170 | if(y === undefined)
171 | this._prevPoint = cc.p(x.x, x.y);
172 | else
173 | this._prevPoint = cc.p(x || 0, y || 0);
174 | }
175 | });
--------------------------------------------------------------------------------
/src/cocos2d/core/scenes/CCLoaderScene.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2011-2012 cocos2d-x.org
3 | Copyright (c) 2013-2014 Chukong Technologies Inc.
4 |
5 | http://www.cocos2d-x.org
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in
15 | all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | THE SOFTWARE.
24 | ****************************************************************************/
25 | /**
26 | * cc.LoaderScene is a scene that you can load it when you loading files
27 | * cc.LoaderScene can present thedownload progress
28 | * @class
29 | * @extends cc.Scene
30 | * @example
31 | * var lc = new cc.LoaderScene();
32 | */
33 | cc.LoaderScene = cc.Scene.extend({
34 | _interval : null,
35 | _label : null,
36 | _className:"LoaderScene",
37 | /**
38 | * Contructor of cc.LoaderScene
39 | * @returns {boolean}
40 | */
41 | init : function(){
42 | var self = this;
43 |
44 | //logo
45 | var logoWidth = 160;
46 | var logoHeight = 200;
47 |
48 | // bg
49 | var bgLayer = self._bgLayer = new cc.LayerColor(cc.color(32, 32, 32, 255));
50 | self.addChild(bgLayer, 0);
51 |
52 | //image move to CCSceneFile.js
53 | var fontSize = 24, lblHeight = -logoHeight / 2 + 100;
54 | if(cc._loaderImage){
55 | //loading logo
56 | cc.loader.loadImg(cc._loaderImage, {isCrossOrigin : false }, function(err, img){
57 | logoWidth = img.width;
58 | logoHeight = img.height;
59 | self._initStage(img, cc.visibleRect.center);
60 | });
61 | fontSize = 14;
62 | lblHeight = -logoHeight / 2 - 10;
63 | }
64 | //loading percent
65 | var label = self._label = new cc.LabelTTF("Loading... 0%", "Arial", fontSize);
66 | label.setPosition(cc.pAdd(cc.visibleRect.center, cc.p(0, lblHeight)));
67 | label.setColor(cc.color(180, 180, 180));
68 | bgLayer.addChild(this._label, 10);
69 | return true;
70 | },
71 |
72 | _initStage: function (img, centerPos) {
73 | var self = this;
74 | var texture2d = self._texture2d = new cc.Texture2D();
75 | texture2d.initWithElement(img);
76 | texture2d.handleLoadedTexture();
77 | var logo = self._logo = new cc.Sprite(texture2d);
78 | logo.setScale(cc.contentScaleFactor());
79 | logo.x = centerPos.x;
80 | logo.y = centerPos.y;
81 | self._bgLayer.addChild(logo, 10);
82 | },
83 | /**
84 | * custom onEnter
85 | */
86 | onEnter: function () {
87 | var self = this;
88 | cc.Node.prototype.onEnter.call(self);
89 | self.schedule(self._startLoading, 0.3);
90 | },
91 | /**
92 | * custom onExit
93 | */
94 | onExit: function () {
95 | cc.Node.prototype.onExit.call(this);
96 | var tmpStr = "Loading... 0%";
97 | this._label.setString(tmpStr);
98 | },
99 |
100 | /**
101 | * init with resources
102 | * @param {Array} resources
103 | * @param {Function|String} cb
104 | */
105 | initWithResources: function (resources, cb) {
106 | if(cc.isString(resources))
107 | resources = [resources];
108 | this.resources = resources || [];
109 | this.cb = cb;
110 | },
111 |
112 | _startLoading: function () {
113 | var self = this;
114 | self.unschedule(self._startLoading);
115 | var res = self.resources;
116 | cc.loader.load(res,
117 | function (result, count, loadedCount) {
118 | var percent = (loadedCount / count * 100) | 0;
119 | percent = Math.min(percent, 100);
120 | self._label.setString("Loading... " + percent + "%");
121 | }, function () {
122 | if (self.cb)
123 | self.cb();
124 | });
125 | }
126 | });
127 | /**
128 | * cc.LoaderScene.preload can present a loaderScene with download progress.
129 | * when all the resource are downloaded it will invoke call function
130 | * @param resources
131 | * @param cb
132 | * @returns {cc.LoaderScene|*}
133 | * @example
134 | * //Example
135 | * cc.LoaderScene.preload(g_resources, function () {
136 | cc.director.runScene(new HelloWorldScene());
137 | }, this);
138 | */
139 | cc.LoaderScene.preload = function(resources, cb){
140 | var _cc = cc;
141 | if(!_cc.loaderScene) {
142 | _cc.loaderScene = new cc.LoaderScene();
143 | _cc.loaderScene.init();
144 | }
145 | _cc.loaderScene.initWithResources(resources, cb);
146 |
147 | cc.director.runScene(_cc.loaderScene);
148 | return _cc.loaderScene;
149 | };
--------------------------------------------------------------------------------
/src/cocos2d/core/platform/CCSAXParser.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | /**
28 | * A SAX Parser
29 | * @class
30 | * @name cc.saxParser
31 | * @extends cc.Class
32 | */
33 | cc.SAXParser = cc.Class.extend(/** @lends cc.saxParser# */{
34 | _parser: null,
35 | _isSupportDOMParser: null,
36 |
37 | /**
38 | * Constructor of cc.SAXParser
39 | */
40 | ctor: function () {
41 | if (window.DOMParser) {
42 | this._isSupportDOMParser = true;
43 | this._parser = new DOMParser();
44 | } else {
45 | this._isSupportDOMParser = false;
46 | }
47 | },
48 |
49 | /**
50 | * @function
51 | * @param {String} xmlTxt
52 | * @return {Document}
53 | */
54 | parse : function(xmlTxt){
55 | return this._parseXML(xmlTxt);
56 | },
57 |
58 | _parseXML: function (textxml) {
59 | // get a reference to the requested corresponding xml file
60 | var xmlDoc;
61 | if (this._isSupportDOMParser) {
62 | xmlDoc = this._parser.parseFromString(textxml, "text/xml");
63 | } else {
64 | // Internet Explorer (untested!)
65 | xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
66 | xmlDoc.async = "false";
67 | xmlDoc.loadXML(textxml);
68 | }
69 | return xmlDoc;
70 | }
71 |
72 | });
73 |
74 | /**
75 | *
76 | * cc.plistParser is a singleton object for parsing plist files
77 | * @class
78 | * @name cc.plistParser
79 | * @extends cc.SAXParser
80 | */
81 | cc.PlistParser = cc.SAXParser.extend(/** @lends cc.plistParser# */{
82 |
83 | /**
84 | * parse a xml string as plist object.
85 | * @param {String} xmlTxt plist xml contents
86 | * @return {*} plist object
87 | */
88 | parse : function (xmlTxt) {
89 | var xmlDoc = this._parseXML(xmlTxt);
90 | var plist = xmlDoc.documentElement;
91 | if (plist.tagName !== 'plist')
92 | throw "Not a plist file!";
93 |
94 | // Get first real node
95 | var node = null;
96 | for (var i = 0, len = plist.childNodes.length; i < len; i++) {
97 | node = plist.childNodes[i];
98 | if (node.nodeType === 1)
99 | break;
100 | }
101 | xmlDoc = null;
102 | return this._parseNode(node);
103 | },
104 |
105 | _parseNode: function (node) {
106 | var data = null, tagName = node.tagName;
107 | if(tagName === "dict"){
108 | data = this._parseDict(node);
109 | }else if(tagName === "array"){
110 | data = this._parseArray(node);
111 | }else if(tagName === "string"){
112 | if (node.childNodes.length === 1)
113 | data = node.firstChild.nodeValue;
114 | else {
115 | //handle Firefox's 4KB nodeValue limit
116 | data = "";
117 | for (var i = 0; i < node.childNodes.length; i++)
118 | data += node.childNodes[i].nodeValue;
119 | }
120 | }else if(tagName === "false"){
121 | data = false;
122 | }else if(tagName === "true"){
123 | data = true;
124 | }else if(tagName === "real"){
125 | data = parseFloat(node.firstChild.nodeValue);
126 | }else if(tagName === "integer"){
127 | data = parseInt(node.firstChild.nodeValue, 10);
128 | }
129 | return data;
130 | },
131 |
132 | _parseArray: function (node) {
133 | var data = [];
134 | for (var i = 0, len = node.childNodes.length; i < len; i++) {
135 | var child = node.childNodes[i];
136 | if (child.nodeType !== 1)
137 | continue;
138 | data.push(this._parseNode(child));
139 | }
140 | return data;
141 | },
142 |
143 | _parseDict: function (node) {
144 | var data = {};
145 | var key = null;
146 | for (var i = 0, len = node.childNodes.length; i < len; i++) {
147 | var child = node.childNodes[i];
148 | if (child.nodeType !== 1)
149 | continue;
150 |
151 | // Grab the key, next noe should be the value
152 | if (child.tagName === 'key')
153 | key = child.firstChild.nodeValue;
154 | else
155 | data[key] = this._parseNode(child); // Parse the value node
156 | }
157 | return data;
158 | }
159 |
160 | });
--------------------------------------------------------------------------------
/src/cocos2d/kazmath/vec4.js:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2008, Luke Benstead.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification,
9 | are permitted provided that the following conditions are met:
10 |
11 | Redistributions of source code must retain the above copyright notice,
12 | this list of conditions and the following disclaimer.
13 | Redistributions in binary form must reproduce the above copyright notice,
14 | this list of conditions and the following disclaimer in the documentation
15 | and/or other materials provided with the distribution.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | (function(cc) {
30 | cc.math.Vec4 = function (x, y, z, w) {
31 | if (x && y === undefined) {
32 | this.x = x.x;
33 | this.y = x.y;
34 | this.z = x.z;
35 | this.w = x.w;
36 | } else {
37 | this.x = x || 0;
38 | this.y = y || 0;
39 | this.z = z || 0;
40 | this.w = w || 0;
41 | }
42 | };
43 | cc.kmVec4 = cc.math.Vec4;
44 | var proto = cc.math.Vec4.prototype;
45 |
46 | proto.fill = function (x, y, z, w) { //=cc.kmVec4Fill
47 | if (x && y === undefined) {
48 | this.x = x.x;
49 | this.y = x.y;
50 | this.z = x.z;
51 | this.w = x.w;
52 | } else {
53 | this.x = x;
54 | this.y = y;
55 | this.z = z;
56 | this.w = w;
57 | }
58 | };
59 |
60 | proto.add = function(vec) { //cc.kmVec4Add
61 | if(!vec)
62 | return this;
63 | this.x += vec.x;
64 | this.y += vec.y;
65 | this.z += vec.z;
66 | this.w += vec.w;
67 | return this;
68 | };
69 |
70 | proto.dot = function(vec){ //cc.kmVec4Dot
71 | return ( this.x * vec.x + this.y * vec.y + this.z * vec.z + this.w * vec.w );
72 | };
73 |
74 | proto.length = function(){ //=cc.kmVec4Length
75 | return Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z) + cc.math.square(this.w));
76 | };
77 |
78 | proto.lengthSq = function(){ //=cc.kmVec4LengthSq
79 | return cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z) + cc.math.square(this.w);
80 | };
81 |
82 | proto.lerp = function(vec, t){ //= cc.kmVec4Lerp
83 | //not implemented
84 | return this;
85 | };
86 |
87 | proto.normalize = function() { // cc.kmVec4Normalize
88 | var l = 1.0 / this.length();
89 | this.x *= l;
90 | this.y *= l;
91 | this.z *= l;
92 | this.w *= l;
93 | return this;
94 | };
95 |
96 | proto.scale = function(scale){ //= cc.kmVec4Scale
97 | /// Scales a vector to the required length. This performs a Normalize before multiplying by S.
98 | this.normalize();
99 | this.x *= scale;
100 | this.y *= scale;
101 | this.z *= scale;
102 | this.w *= scale;
103 | return this;
104 | };
105 |
106 | proto.subtract = function(vec) {
107 | this.x -= vec.x;
108 | this.y -= vec.y;
109 | this.z -= vec.z;
110 | this.w -= vec.w;
111 | };
112 |
113 | proto.transform = function(mat4) {
114 | var x = this.x, y = this.y, z = this.z, w = this.w, mat = mat4.mat;
115 | this.x = x * mat[0] + y * mat[4] + z * mat[8] + w * mat[12];
116 | this.y = x * mat[1] + y * mat[5] + z * mat[9] + w * mat[13];
117 | this.z = x * mat[2] + y * mat[6] + z * mat[10] + w * mat[14];
118 | this.w = x * mat[3] + y * mat[7] + z * mat[11] + w * mat[15];
119 | return this;
120 | };
121 |
122 | cc.math.Vec4.transformArray = function(vecArray, mat4){
123 | var retArray = [];
124 | for (var i = 0; i < vecArray.length; i++) {
125 | var selVec = new cc.math.Vec4(vecArray[i]);
126 | selVec.transform(mat4);
127 | retArray.push(selVec);
128 | }
129 | return retArray;
130 | };
131 |
132 | proto.equals = function(vec){ //=cc.kmVec4AreEqual
133 | var EPSILON = cc.math.EPSILON;
134 | return (this.x < vec.x + EPSILON && this.x > vec.x - EPSILON) &&
135 | (this.y < vec.y + EPSILON && this.y > vec.y - EPSILON) &&
136 | (this.z < vec.z + EPSILON && this.z > vec.z - EPSILON) &&
137 | (this.w < vec.w + EPSILON && this.w > vec.w - EPSILON);
138 | };
139 |
140 | proto.assignFrom = function(vec) { //= cc.kmVec4Assign
141 | this.x = vec.x;
142 | this.y = vec.y;
143 | this.z = vec.z;
144 | this.w = vec.w;
145 | return this;
146 | };
147 |
148 | proto.toTypeArray = function(){ //cc.kmVec4ToTypeArray
149 | var tyArr = new Float32Array(4);
150 | tyArr[0] = this.x;
151 | tyArr[1] = this.y;
152 | tyArr[2] = this.z;
153 | tyArr[3] = this.w;
154 | return tyArr;
155 | };
156 | })(cc);
157 |
158 |
159 |
--------------------------------------------------------------------------------
/src/cocos2d/transitions/CCTransitionPageTurn.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | /**
28 | * A transition which peels back the bottom right hand corner of a scene
29 | * to transition to the scene beneath it simulating a page turn.
30 | *
31 | * This uses a 3DAction so it's strongly recommended that depth buffering
32 | * is turned on in cc.director using:
33 | *
34 | * cc.director.setDepthBufferFormat(kDepthBuffer16);
35 | * @class
36 | * @extends cc.TransitionScene
37 | * @param {Number} t time in seconds
38 | * @param {cc.Scene} scene
39 | * @param {Boolean} backwards
40 | * @example
41 | * var trans = new cc.TransitionPageTurn(t, scene, backwards);
42 | */
43 | cc.TransitionPageTurn = cc.TransitionScene.extend(/** @lends cc.TransitionPageTurn# */{
44 |
45 | /**
46 | * @param {Number} t time in seconds
47 | * @param {cc.Scene} scene
48 | * @param {Boolean} backwards
49 | */
50 | ctor:function (t, scene, backwards) {
51 | cc.TransitionScene.prototype.ctor.call(this);
52 | this._gridProxy = new cc.NodeGrid();
53 | this.initWithDuration(t, scene, backwards);
54 | },
55 |
56 | /**
57 | * @type Boolean
58 | */
59 | _back:true,
60 | _gridProxy: null,
61 | _className:"TransitionPageTurn",
62 |
63 | /**
64 | * Creates a base transition with duration and incoming scene.
65 | * If back is true then the effect is reversed to appear as if the incoming
66 | * scene is being turned from left over the outgoing scene.
67 | * @param {Number} t time in seconds
68 | * @param {cc.Scene} scene
69 | * @param {Boolean} backwards
70 | * @return {Boolean}
71 | */
72 | initWithDuration:function (t, scene, backwards) {
73 | // XXX: needed before [super init]
74 | this._back = backwards;
75 |
76 | if (cc.TransitionScene.prototype.initWithDuration.call(this, t, scene)) {
77 | // do something
78 | }
79 | return true;
80 | },
81 |
82 | /**
83 | * @param {cc.Size} vector
84 | * @return {cc.ReverseTime|cc.TransitionScene}
85 | */
86 | actionWithSize:function (vector) {
87 | if (this._back)
88 | return cc.reverseTime(cc.pageTurn3D(this._duration, vector)); // Get hold of the PageTurn3DAction
89 | else
90 | return cc.pageTurn3D(this._duration, vector); // Get hold of the PageTurn3DAction
91 | },
92 |
93 | /**
94 | * custom on enter
95 | */
96 | onEnter:function () {
97 | cc.TransitionScene.prototype.onEnter.call(this);
98 | var winSize = cc.director.getWinSize();
99 | var x, y;
100 | if (winSize.width > winSize.height) {
101 | x = 16;
102 | y = 12;
103 | } else {
104 | x = 12;
105 | y = 16;
106 | }
107 |
108 | var action = this.actionWithSize(cc.size(x, y)), gridProxy = this._gridProxy;
109 |
110 | if (!this._back) {
111 | gridProxy.setTarget(this._outScene);
112 | gridProxy.onEnter();
113 | gridProxy.runAction( cc.sequence(action,cc.callFunc(this.finish, this),cc.stopGrid()));
114 | } else {
115 | gridProxy.setTarget(this._inScene);
116 | gridProxy.onEnter();
117 | // to prevent initial flicker
118 | this._inScene.visible = false;
119 | gridProxy.runAction(
120 | cc.sequence(action, cc.callFunc(this.finish, this), cc.stopGrid())
121 | );
122 | this._inScene.runAction(cc.show());
123 | }
124 | },
125 |
126 | visit: function(){
127 | //cc.TransitionScene.prototype.visit.call(this);
128 | if(this._back)
129 | this._outScene.visit();
130 | else
131 | this._inScene.visit();
132 | this._gridProxy.visit();
133 | },
134 |
135 | _sceneOrder:function () {
136 | this._isInSceneOnTop = this._back;
137 | }
138 | });
139 |
140 | /**
141 | * Creates a base transition with duration and incoming scene.
142 | * If back is true then the effect is reversed to appear as if the incoming
143 | * scene is being turned from left over the outgoing scene.
144 | * @deprecated since v3.0,please use new cc.TransitionPageTurn(t, scene, backwards) instead.
145 | * @param {Number} t time in seconds
146 | * @param {cc.Scene} scene
147 | * @param {Boolean} backwards
148 | * @return {cc.TransitionPageTurn}
149 | */
150 | cc.TransitionPageTurn.create = function (t, scene, backwards) {
151 | return new cc.TransitionPageTurn(t, scene, backwards);
152 | };
153 |
--------------------------------------------------------------------------------
/src/cocos2d/core/platform/CCScreen.js:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 |
6 | http://www.cocos2d-x.org
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | ****************************************************************************/
26 |
27 | /**
28 | * The fullscreen API provides an easy way for web content to be presented using the user's entire screen.
29 | * It's invalid on safari, QQbrowser and android browser
30 | * @class
31 | * @name cc.screen
32 | */
33 | cc.screen = /** @lends cc.screen# */{
34 | _supportsFullScreen: false,
35 | // the pre fullscreenchange function
36 | _preOnFullScreenChange: null,
37 | _touchEvent: "",
38 | _fn: null,
39 | // Function mapping for cross browser support
40 | _fnMap: [
41 | [
42 | 'requestFullscreen',
43 | 'exitFullscreen',
44 | 'fullscreenchange',
45 | 'fullscreenEnabled',
46 | 'fullscreenElement'
47 | ],
48 | [
49 | 'requestFullScreen',
50 | 'exitFullScreen',
51 | 'fullScreenchange',
52 | 'fullScreenEnabled',
53 | 'fullScreenElement'
54 | ],
55 | [
56 | 'webkitRequestFullScreen',
57 | 'webkitCancelFullScreen',
58 | 'webkitfullscreenchange',
59 | 'webkitIsFullScreen',
60 | 'webkitCurrentFullScreenElement'
61 | ],
62 | [
63 | 'mozRequestFullScreen',
64 | 'mozCancelFullScreen',
65 | 'mozfullscreenchange',
66 | 'mozFullScreen',
67 | 'mozFullScreenElement'
68 | ],
69 | [
70 | 'msRequestFullscreen',
71 | 'msExitFullscreen',
72 | 'MSFullscreenChange',
73 | 'msFullscreenEnabled',
74 | 'msFullscreenElement'
75 | ]
76 | ],
77 |
78 | /**
79 | * initialize
80 | * @function
81 | */
82 | init: function () {
83 | this._fn = {};
84 | var i, val, map = this._fnMap, valL;
85 | for (i = 0, l = map.length; i < l; i++) {
86 | val = map[i];
87 | if (val && val[1] in document) {
88 | for (i = 0, valL = val.length; i < valL; i++) {
89 | this._fn[map[0][i]] = val[i];
90 | }
91 | break;
92 | }
93 | }
94 |
95 | this._supportsFullScreen = (typeof this._fn.requestFullscreen !== 'undefined');
96 | this._touchEvent = ('ontouchstart' in window) ? 'touchstart' : 'mousedown';
97 | },
98 |
99 | /**
100 | * return true if it's full now.
101 | * @returns {Boolean}
102 | */
103 | fullScreen: function () {
104 | return this._supportsFullScreen && document[this._fn.fullscreenElement];
105 | },
106 |
107 | /**
108 | * change the screen to full mode.
109 | * @param {Element} element
110 | * @param {Function} onFullScreenChange
111 | */
112 | requestFullScreen: function (element, onFullScreenChange) {
113 | if (!this._supportsFullScreen) {
114 | return;
115 | }
116 |
117 | element = element || document.documentElement;
118 |
119 | if (onFullScreenChange) {
120 | var eventName = this._fn.fullscreenchange;
121 | if (this._preOnFullScreenChange) {
122 | document.removeEventListener(eventName, this._preOnFullScreenChange);
123 | }
124 | this._preOnFullScreenChange = onFullScreenChange;
125 | cc._addEventListener(document, eventName, onFullScreenChange, false);
126 | }
127 |
128 | return element[this._fn.requestFullscreen]();
129 | },
130 |
131 | /**
132 | * exit the full mode.
133 | * @return {Boolean}
134 | */
135 | exitFullScreen: function () {
136 | return this._supportsFullScreen ? document[this._fn.exitFullscreen]() : true;
137 | },
138 |
139 | /**
140 | * Automatically request full screen with a touch/click event
141 | * @param {Element} element
142 | * @param {Function} onFullScreenChange
143 | */
144 | autoFullScreen: function (element, onFullScreenChange) {
145 | element = element || document.body;
146 | var touchTarget = cc._canvas || element;
147 | var theScreen = this;
148 | // Function bind will be too complicated here because we need the callback function's reference to remove the listener
149 | function callback() {
150 | theScreen.requestFullScreen(element, onFullScreenChange);
151 | touchTarget.removeEventListener(theScreen._touchEvent, callback);
152 | }
153 | this.requestFullScreen(element, onFullScreenChange);
154 | cc._addEventListener(touchTarget, this._touchEvent, callback);
155 | }
156 | };
157 | cc.screen.init();
--------------------------------------------------------------------------------
/src/cocos2d/kazmath/ray2.js:
--------------------------------------------------------------------------------
1 | /**
2 | Copyright (c) 2008-2010 Ricardo Quesada
3 | Copyright (c) 2011-2012 cocos2d-x.org
4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
5 | Copyright (c) 2008, Luke Benstead.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification,
9 | are permitted provided that the following conditions are met:
10 |
11 | Redistributions of source code must retain the above copyright notice,
12 | this list of conditions and the following disclaimer.
13 | Redistributions in binary form must reproduce the above copyright notice,
14 | this list of conditions and the following disclaimer in the documentation
15 | and/or other materials provided with the distribution.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | (function(cc){
30 | cc.math.Ray2 = function (start, dir) { // = cc.kmRay2
31 | this.start = start || new cc.math.Vec2();
32 | this.dir = dir || new cc.math.Vec2();
33 | };
34 |
35 | cc.math.Ray2.prototype.fill = function (px, py, vx, vy) { // = cc.kmRay2Fill
36 | this.start.x = px;
37 | this.start.y = py;
38 | this.dir.x = vx;
39 | this.dir.y = vy;
40 | };
41 |
42 | cc.math.Ray2.prototype.intersectLineSegment = function (p1, p2, intersection) { // = cc.kmRay2IntersectLineSegment
43 | var x1 = this.start.x, y1 = this.start.y;
44 | var x2 = this.start.x + this.dir.x, y2 = this.start.y + this.dir.y;
45 | var x3 = p1.x, y3 = p1.y;
46 | var x4 = p2.x, y4 = p2.y;
47 |
48 | var denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
49 | var ua, x, y;
50 | //If denom is zero, the lines are parallel
51 | if (denom > -cc.math.EPSILON && denom < cc.math.EPSILON)
52 | return false;
53 |
54 | ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denom;
55 | //var ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / denom;
56 |
57 | x = x1 + ua * (x2 - x1);
58 | y = y1 + ua * (y2 - y1);
59 |
60 | if (x < Math.min(p1.x, p2.x) - cc.math.EPSILON ||
61 | x > Math.max(p1.x, p2.x) + cc.math.EPSILON ||
62 | y < Math.min(p1.y, p2.y) - cc.math.EPSILON ||
63 | y > Math.max(p1.y, p2.y) + cc.math.EPSILON) {
64 | //Outside of line
65 | //printf("Outside of line, %f %f (%f %f)(%f, %f)\n", x, y, p1.x, p1.y, p2.x, p2.y);
66 | return false;
67 | }
68 |
69 | if (x < Math.min(x1, x2) - cc.math.EPSILON ||
70 | x > Math.max(x1, x2) + cc.math.EPSILON ||
71 | y < Math.min(y1, y2) - cc.math.EPSILON ||
72 | y > Math.max(y1, y2) + cc.math.EPSILON) {
73 | //printf("Outside of ray, %f %f (%f %f)(%f, %f)\n", x, y, x1, y1, x2, y2);
74 | return false;
75 | }
76 |
77 | intersection.x = x;
78 | intersection.y = y;
79 | return true;
80 | };
81 |
82 | function calculate_line_normal(p1, p2, normalOut){
83 | var tmp = new cc.math.Vec2(p2);
84 | tmp.subtract(p1);
85 |
86 | normalOut.x = -tmp.y;
87 | normalOut.y = tmp.x;
88 | normalOut.normalize();
89 | //TODO: should check that the normal is pointing out of the triangle
90 | }
91 |
92 | cc.math.Ray2.prototype.intersectTriangle = function(p1, p2, p3, intersection, normal_out){
93 | var intersect = new cc.math.Vec2(), final_intersect = new cc.math.Vec2();
94 | var normal = new cc.math.Vec2(), distance = 10000.0, intersected = false;
95 | var this_distance;
96 |
97 | if(this.intersectLineSegment(p1, p2, intersect)) {
98 | intersected = true;
99 | this_distance = intersect.subtract(this.start).length();
100 | if(this_distance < distance) {
101 | final_intersect.x = intersect.x;
102 | final_intersect.y = intersect.y;
103 | distance = this_distance;
104 | calculate_line_normal(p1, p2, normal);
105 | }
106 | }
107 |
108 | if(this.intersectLineSegment(p2, p3, intersect)) {
109 | intersected = true;
110 | this_distance = intersect.subtract(this.start).length();
111 | if(this_distance < distance) {
112 | final_intersect.x = intersect.x;
113 | final_intersect.y = intersect.y;
114 | distance = this_distance;
115 | calculate_line_normal(p2, p3, normal);
116 | }
117 | }
118 |
119 | if(this.intersectLineSegment(p3, p1, intersect)) {
120 | intersected = true;
121 | this_distance = intersect.subtract(this.start).length();
122 | if(this_distance < distance) {
123 | final_intersect.x = intersect.x;
124 | final_intersect.y = intersect.y;
125 | distance = this_distance;
126 | calculate_line_normal(p3, p1, normal);
127 | }
128 | }
129 |
130 | if(intersected) {
131 | intersection.x = final_intersect.x;
132 | intersection.y = final_intersect.y;
133 | if(normal_out) {
134 | normal_out.x = normal.x;
135 | normal_out.y = normal.y;
136 | }
137 | }
138 | return intersected;
139 | };
140 | })(cc);
141 |
--------------------------------------------------------------------------------