From e02ebf309fe3a0b2db15949d5e7cdda2fda210e7 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Sun, 29 May 2016 00:22:46 +0800 Subject: [PATCH 01/17] log the engine size when building html5 --- gulp/tasks/build.js | 59 +++++++++++++++++++++++++++++++++++---------- gulpfile.js | 3 ++- package.json | 2 ++ 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/gulp/tasks/build.js b/gulp/tasks/build.js index 544de5fb48..cb0545bdaf 100644 --- a/gulp/tasks/build.js +++ b/gulp/tasks/build.js @@ -29,10 +29,13 @@ var Del = require('del'); var gulp = require('gulp'); var mirror = require('gulp-mirror'); +var pipe = require('multipipe'); var uglify = require('gulp-uglify'); var rename = require('gulp-rename'); var sourcemaps = require('gulp-sourcemaps'); var es = require('event-stream'); +var size = require('gulp-size'); +var chalk = require('chalk'); var browserify = require('browserify'); var source = require('vinyl-source-stream'); @@ -86,31 +89,61 @@ function getUglifyOptions (minify, global_defs) { } } +function printSizes (sizeGetter, minSizeGetter, zippedSizeGetter) { + return es.through(null, function () { + console.log('Size of web engine: zipped: ' + chalk.cyan(zippedSizeGetter.size.toLocaleString() + 'B') + + ', minimized: ' + chalk.cyan(minSizeGetter.size.toLocaleString() + 'B') + + ', raw: ' + chalk.cyan(sizeGetter.size.toLocaleString() + 'B') + + ', compression ratio: ' + chalk.magenta((zippedSizeGetter.size / sizeGetter.size * 100).toFixed(2) + '%')); + this.emit('end'); + }); +} + function rebundle_html_dev_min(bundler) { - console.log('compiling...'); + console.log('Compiling ' + paths.outFileDev + ' and ' + paths.outFile + ' ...'); - var dev = uglify(getUglifyOptions(false, { - CC_EDITOR: false, - CC_DEV: true, - CC_TEST: false, - CC_JSB: false - })); + function createSizeGetter (gzip) { + return size({ + gzip: gzip, + pretty: false, + showTotal: false, + showFiles: false, + }); + } - var min = rename({ suffix: '-min' }); - min.pipe(uglify(getUglifyOptions(true, { + var sizeGetter = createSizeGetter(false); + var minSizeGetter = createSizeGetter(false); + var zippedSizeGetter = createSizeGetter(true); + + var devPipes = [ + uglify(getUglifyOptions(false, { + CC_EDITOR: false, + CC_DEV: true, + CC_TEST: false, + CC_JSB: false + })), + sizeGetter + ]; + var minPipes = [ + rename(paths.outFile), + uglify(getUglifyOptions(true, { CC_EDITOR: false, CC_DEV: false, CC_TEST: false, CC_JSB: false - }))); + })), + minSizeGetter, + zippedSizeGetter, + ]; return bundler.bundle() .on('error', handleErrors.handler) .pipe(handleErrors()) - .pipe(source(paths.outFile)) + .pipe(source(paths.outFileDev)) .pipe(buffer()) .pipe(sourcemaps.init({loadMaps: true})) - .pipe(mirror(dev, min)) + .pipe(mirror(pipe(devPipes), pipe(minPipes))) + .pipe(printSizes(sizeGetter, minSizeGetter, zippedSizeGetter)) .pipe(sourcemaps.write('./', {sourceRoot: './', addComment: true})) .pipe(gulp.dest(paths.outDir)); } @@ -128,7 +161,7 @@ function rebundle(bundler, name, options) { .pipe(buffer()); if (macros) { - console.log('compiling...'); + console.log('Compiling ' + name + ' ...'); if (sourceMaps) { bundle = bundle.pipe(sourcemaps.init({loadMaps: true})); } diff --git a/gulpfile.js b/gulpfile.js index 2850909777..c1036f20e1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -34,7 +34,8 @@ paths = { src: './src', jsEntry: './index.js', outDir: './bin', - outFile: 'cocos2d-js.js', + outFileDev: 'cocos2d-js.js', + outFile: 'cocos2d-js-min.js', jsb: { entries: [ diff --git a/package.json b/package.json index 338e408aad..8071bae5fc 100644 --- a/package.json +++ b/package.json @@ -26,10 +26,12 @@ "gulp-plumber": "0.6.6", "gulp-rename": "1.2.2", "gulp-shell": "0.4.1", + "gulp-size": "2.1.0", "gulp-sourcemaps": "1.5.2", "gulp-uglify": "1.5.3", "gulp-util": "3.0.6", "jshint-stylish": "2.1.0", + "multipipe": "0.3.0", "require-dir": "0.3.0", "vinyl": "1.1.0", "vinyl-buffer": "1.0.0", From 92f9c79edeb5917f660473441a2046269cf207b9 Mon Sep 17 00:00:00 2001 From: ViusualSJ Date: Mon, 30 May 2016 11:09:28 +0800 Subject: [PATCH 02/17] video visible --- cocos2d/core/videoplayer/CCSGVideoPlayer.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/videoplayer/CCSGVideoPlayer.js b/cocos2d/core/videoplayer/CCSGVideoPlayer.js index d4f4c23606..b617dcac92 100644 --- a/cocos2d/core/videoplayer/CCSGVideoPlayer.js +++ b/cocos2d/core/videoplayer/CCSGVideoPlayer.js @@ -139,6 +139,11 @@ _ccsg.VideoPlayer = _ccsg.Node.extend(/** @lends _ccsg.VideoPlayer# */{ var index = list.indexOf(this); if(index !== -1) list.splice(index, 1); + }, + + setVisible: function ( visible ) { + _ccsg.Node.prototype.setVisible.call(this, visible); + this._renderCmd.updateDisplay(); } }); @@ -298,7 +303,6 @@ _ccsg.VideoPlayer.EventType = { node.setContentSize(video.clientWidth, video.clientHeight); video.removeEventListener(polyfill.event, cb); video.currentTime = 0; - video.style["visibility"] = "visible"; //IOS does not display video images video.play(); if(!this._played){ @@ -307,6 +311,7 @@ _ccsg.VideoPlayer.EventType = { } video.currentTime = 0; } + this.updateDisplay(); this.updateMatrix(this._worldTransform); }.bind(this); video.addEventListener(polyfill.event, cb); @@ -354,6 +359,18 @@ _ccsg.VideoPlayer.EventType = { }); }; + proto.updateDisplay = function () { + var node = this._node; + if (!this._video) return; + var video = this._video; + if (node.visible) { + video.style.visibility = 'visible'; + } else { + video.style.visibility = 'hidden'; + video.pause(); + } + }; + proto.createDom = function () { var video = document.createElement('video'); video.style.position = "absolute"; From f3cda54407d40150e47265c5cf29333d8db4eee2 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Mon, 30 May 2016 14:24:31 +0800 Subject: [PATCH 03/17] perfect game and director pause / resume API --- cocos2d/core/CCDirector.js | 4 ++-- cocos2d/core/CCGame.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 1598d17e5d..9837408cba 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -405,7 +405,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ /** * !#en Pause the director's ticker. - * !#zh 暂停正在运行的场景。 + * !#zh 暂停正在运行的场景,该暂停只会停止 Scheduler,但是不会停止渲染和 UI 响应。 * @method pause */ pause: function () { @@ -816,7 +816,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ /** * !#en Resume director after pause, if the current scene is not paused, nothing will happen. - * !#zh 恢复暂停场景, 如果当前场景没有暂停将没任何事情发生。 + * !#zh 恢复暂停场景,恢复 Scheduler,如果当前场景没有暂停将没任何事情发生。 * @method resume */ resume: function () { diff --git a/cocos2d/core/CCGame.js b/cocos2d/core/CCGame.js index 2ce30aa4b7..4aefa82ddd 100644 --- a/cocos2d/core/CCGame.js +++ b/cocos2d/core/CCGame.js @@ -240,8 +240,8 @@ var game = /** @lends cc.game# */{ }, /** - * !#en Pause the game. - * !#zh 暂停游戏。 + * !#en Pause the game,pause main loop. + * !#zh 暂停游戏,暂停的是整个主循环。 * @method pause */ pause: function () { @@ -257,7 +257,7 @@ var game = /** @lends cc.game# */{ /** * !#en Resume the game from pause. - * !#zh 继续游戏 + * !#zh 继续游戏,继续的是整个主循环。 * @method resume */ resume: function () { From 563d6fe7fcfec25fb0b62048b2565e8e59a4a1be Mon Sep 17 00:00:00 2001 From: Johnny Wu Date: Mon, 30 May 2016 17:31:26 +0800 Subject: [PATCH 04/17] remove deprected electron code --- test/lib/spawn-runner.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lib/spawn-runner.js b/test/lib/spawn-runner.js index c5e790cb91..747859be4b 100644 --- a/test/lib/spawn-runner.js +++ b/test/lib/spawn-runner.js @@ -4,7 +4,7 @@ if (cc.sys.platform === cc.sys.EDITOR_CORE) { var Ipc = require('ipc'); var Path = require('path'); var Url = require('url'); - var BrowserWindow = require('browser-window'); + var Electron = require('electron'); var spawnWorker = function (title, scriptUrl, debug) { describe(title, function () { @@ -32,7 +32,7 @@ if (cc.sys.platform === cc.sys.EDITOR_CORE) { done(); }); - win = new BrowserWindow({ + win = new Electron.BrowserWindow({ title: title, width: 400, height: 400, From 9b179c2b1191b44bd72fba64b904736e7ea62c4f Mon Sep 17 00:00:00 2001 From: ViusualSJ Date: Mon, 30 May 2016 18:38:38 +0800 Subject: [PATCH 05/17] Fixed video position bug --- cocos2d/core/videoplayer/CCSGVideoPlayer.js | 49 +++++++++++++++------ 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/cocos2d/core/videoplayer/CCSGVideoPlayer.js b/cocos2d/core/videoplayer/CCSGVideoPlayer.js index b617dcac92..b38000d954 100644 --- a/cocos2d/core/videoplayer/CCSGVideoPlayer.js +++ b/cocos2d/core/videoplayer/CCSGVideoPlayer.js @@ -212,14 +212,19 @@ _ccsg.VideoPlayer.EventType = { video._polyfill.canPlayType.push(".webm"); })(); - if(cc.sys.OS_IOS === cc.sys.os){ - video._polyfill.devicePixelRatio = true; - video._polyfill.event = "progress"; - } if(cc.sys.browserType === cc.sys.BROWSER_TYPE_FIREFOX){ video._polyfill.autoplayAfterOperation = true; } + if ( + cc.sys.OS_ANDROID === cc.sys.os && ( + cc.sys.browserType === cc.sys.BROWSER_TYPE_SOUGOU || + cc.sys.browserType === cc.sys.BROWSER_TYPE_360 + ) + ) { + video._polyfill.zoomInvalid = true; + } + var style = document.createElement("style"); style.innerHTML = ".cocosVideo:-moz-full-screen{transform:matrix(1,0,0,1,0,0) !important;}" + ".cocosVideo:full-screen{transform:matrix(1,0,0,1,0,0) !important;}" + @@ -256,17 +261,27 @@ _ccsg.VideoPlayer.EventType = { proto.updateMatrix = function () { if (!this._video) return; var node = this._node, scaleX = cc.view._scaleX, scaleY = cc.view._scaleY; + var dpr = cc.view._devicePixelRatio; var t = node.getNodeToWorldTransform(); if (!t) return; - if(polyfill.devicePixelRatio){ - var dpr = window.devicePixelRatio; - scaleX /= dpr; - scaleY /= dpr; + scaleX /= dpr; + scaleY /= dpr; + + var container = cc.container; + var a = t.a * scaleX, b = t.b, c = t.c, d = t.d * scaleY; + + var offsetX = container && container.style.paddingLeft && parseInt(container.style.paddingLeft); + var offsetY = container && container.style.paddingBottom && parseInt(container.style.paddingBottom); + var tx = t.tx * scaleX + offsetX, ty = t.ty * scaleY + offsetY; + + if (polyfill.zoomInvalid) { + this.updateSize(node._contentSize.width * a, node._contentSize.height * d); + a = 1; + d = 1; } - var a = t.a * scaleX, b = t.b, c = t.c, d = t.d * scaleY; - var matrix = "matrix(" + a + "," + -b + "," + -c + "," + d + "," + t.tx + "," + -t.ty + ")"; + var matrix = "matrix(" + a + "," + -b + "," + -c + "," + d + "," + tx + "," + -ty + ")"; this._video.style['transform'] = matrix; this._video.style['-webkit-transform'] = matrix; this._video.style['transform-origin'] = '0px 100% 0px'; @@ -300,7 +315,7 @@ _ccsg.VideoPlayer.EventType = { if(this._loaded == true) return; this._loaded = true; - node.setContentSize(video.clientWidth, video.clientHeight); + node.setContentSize(node._contentSize.width, node._contentSize.height); video.removeEventListener(polyfill.event, cb); video.currentTime = 0; //IOS does not display video images @@ -312,7 +327,7 @@ _ccsg.VideoPlayer.EventType = { video.currentTime = 0; } this.updateDisplay(); - this.updateMatrix(this._worldTransform); + this.updateMatrix(); }.bind(this); video.addEventListener(polyfill.event, cb); @@ -458,7 +473,15 @@ _ccsg.VideoPlayer.EventType = { var video = this._video; if (!video) return; - video.currentTime = sec; + if (this._loaded) { + video.currentTime = sec; + } else { + var cb = function () { + video.currentTime = sec; + video.removeEventListener(polyfill.event, cb); + }; + video.addEventListener(polyfill.event, cb); + } if(_ccsg.VideoPlayer._polyfill.autoplayAfterOperation && this.isPlaying()){ setTimeout(function(){ video.play(); From c86e7b26dcf8b49974b8aaf894917cf9a5d20db4 Mon Sep 17 00:00:00 2001 From: ViusualSJ Date: Mon, 30 May 2016 18:44:15 +0800 Subject: [PATCH 06/17] review updateDisplay -> updateVisibility --- cocos2d/core/videoplayer/CCSGVideoPlayer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/videoplayer/CCSGVideoPlayer.js b/cocos2d/core/videoplayer/CCSGVideoPlayer.js index b38000d954..1cf40db0c7 100644 --- a/cocos2d/core/videoplayer/CCSGVideoPlayer.js +++ b/cocos2d/core/videoplayer/CCSGVideoPlayer.js @@ -143,7 +143,7 @@ _ccsg.VideoPlayer = _ccsg.Node.extend(/** @lends _ccsg.VideoPlayer# */{ setVisible: function ( visible ) { _ccsg.Node.prototype.setVisible.call(this, visible); - this._renderCmd.updateDisplay(); + this._renderCmd.updateVisibility(); } }); @@ -326,7 +326,7 @@ _ccsg.VideoPlayer.EventType = { } video.currentTime = 0; } - this.updateDisplay(); + this.updateVisibility(); this.updateMatrix(); }.bind(this); video.addEventListener(polyfill.event, cb); @@ -374,7 +374,7 @@ _ccsg.VideoPlayer.EventType = { }); }; - proto.updateDisplay = function () { + proto.updateVisibility = function () { var node = this._node; if (!this._video) return; var video = this._video; From 97f7d95074ca76e38ecffe6fa5f72f9d0a742a63 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 30 May 2016 20:00:58 +0800 Subject: [PATCH 07/17] add scroll to fixed position API --- cocos2d/core/components/CCScrollView.js | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/cocos2d/core/components/CCScrollView.js b/cocos2d/core/components/CCScrollView.js index 5a802b1ff3..593889af50 100644 --- a/cocos2d/core/components/CCScrollView.js +++ b/cocos2d/core/components/CCScrollView.js @@ -484,6 +484,44 @@ var ScrollView = cc.Class({ } }, + + /** + * !#en Scroll with an offset related to the ScrollView's origin. + * !#zh 视图内容在规定时间内将滚动到 ScrollView 相对偏移位置上。 + * @method scrollToOffset + * @param {Vec2} position - A Vec2, the value of which each axis between 0 and (contentSize.width/height - scrollSize.width/height). + * @param {Number} [timeInSecond=0] - Scroll time in second, if you don't pass timeInSecond, + * the content will jump to the specific offset of ScrollView immediately. + * @param {Boolean} [attenuated=true] - Whether the scroll acceleration attenuated, default is true. + * @example + * // Scroll to middle position in 0.1 second in x-axis + * var maxScrollOffset = this.getMaxScrollOffset(); + * scrollView.scrollToOffset(cc.p(maxScrollOffset.x / 2, 0), 0.1); + */ + scrollToOffset: function(position, timeInSecond, attenuated) { + var maxScrollOffset = this.getMaxScrollOffset(); + + var anchor = cc.pClamp(cc.p(position.x / maxScrollOffset.x, (maxScrollOffset.y - position.y ) / maxScrollOffset.y), + cc.p(0, 0), cc.p(1, 1)); + + this.scrollTo(anchor, timeInSecond, attenuated); + }, + + getScrollOffset: function() { + var bottomDeta = Math.abs(this._getContentBottomBoundary() - this._bottomBoundary); + var leftDeta = Math.abs(this._getContentLeftBoundary() - this._leftBoundary); + var maxScrollOffset = this.getMaxScrollOffset(); + + return cc.p(leftDeta, maxScrollOffset.y - bottomDeta); + }, + + getMaxScrollOffset: function() { + var scrollSize = this.node.getContentSize(); + var contentSize = this.content.getContentSize(); + + return cc.p(contentSize.width - scrollSize.width, contentSize.height - scrollSize.height); + }, + /** * !#en Scroll the content to the horizontal percent position of ScrollView. * !#zh 视图内容在规定时间内将滚动到 ScrollView 水平方向的百分比位置上。 From 0118566038952287c41bdce4a2c68526f82e6c99 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Tue, 31 May 2016 09:46:04 +0800 Subject: [PATCH 08/17] add API docs --- cocos2d/core/components/CCScrollView.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cocos2d/core/components/CCScrollView.js b/cocos2d/core/components/CCScrollView.js index 593889af50..5e55fdc4ca 100644 --- a/cocos2d/core/components/CCScrollView.js +++ b/cocos2d/core/components/CCScrollView.js @@ -486,10 +486,11 @@ var ScrollView = cc.Class({ /** - * !#en Scroll with an offset related to the ScrollView's origin. - * !#zh 视图内容在规定时间内将滚动到 ScrollView 相对偏移位置上。 + * !#en Scroll with an offset related to the ScrollView's top left origin, if timeInSecond is omitted, then it will jump to the + * specific offset immediately. + * !#zh 视图内容在规定时间内将滚动到 ScrollView 相对左上角原点的偏移位置, 如果 timeInSecond参数不传,则立即滚动到指定偏移位置。 * @method scrollToOffset - * @param {Vec2} position - A Vec2, the value of which each axis between 0 and (contentSize.width/height - scrollSize.width/height). + * @param {Vec2} offset - A Vec2, the value of which each axis between 0 and maxScrollOffset * @param {Number} [timeInSecond=0] - Scroll time in second, if you don't pass timeInSecond, * the content will jump to the specific offset of ScrollView immediately. * @param {Boolean} [attenuated=true] - Whether the scroll acceleration attenuated, default is true. @@ -498,15 +499,21 @@ var ScrollView = cc.Class({ * var maxScrollOffset = this.getMaxScrollOffset(); * scrollView.scrollToOffset(cc.p(maxScrollOffset.x / 2, 0), 0.1); */ - scrollToOffset: function(position, timeInSecond, attenuated) { + scrollToOffset: function(offset, timeInSecond, attenuated) { var maxScrollOffset = this.getMaxScrollOffset(); - var anchor = cc.pClamp(cc.p(position.x / maxScrollOffset.x, (maxScrollOffset.y - position.y ) / maxScrollOffset.y), + var anchor = cc.pClamp(cc.p(offset.x / maxScrollOffset.x, (maxScrollOffset.y - offset.y ) / maxScrollOffset.y), cc.p(0, 0), cc.p(1, 1)); this.scrollTo(anchor, timeInSecond, attenuated); }, + /** + * !#en Get the current scroll offset related to scrollview 's top left origin. + * !#zh 获取滚动视图相对于左上角原点的当前滚动偏移 + * @method getScrollOffset + * @return {Vec2} - A Vec2 value indicate the current scroll offset. + */ getScrollOffset: function() { var bottomDeta = Math.abs(this._getContentBottomBoundary() - this._bottomBoundary); var leftDeta = Math.abs(this._getContentLeftBoundary() - this._leftBoundary); @@ -515,6 +522,12 @@ var ScrollView = cc.Class({ return cc.p(leftDeta, maxScrollOffset.y - bottomDeta); }, + /** + * !#en Get the maximize available scroll offset + * !#zh 获取滚动视图最大可以滚动的偏移量 + * @method getMaxScrollOffset + * @return {Ve2c} - A Vec2 value indicate the maximize scroll offset in x and y axis. + */ getMaxScrollOffset: function() { var scrollSize = this.node.getContentSize(); var contentSize = this.content.getContentSize(); From 341633201f8e0d1de86d19d05e32e6365a9dc37a Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Tue, 31 May 2016 10:29:46 +0800 Subject: [PATCH 09/17] improve docs --- cocos2d/core/components/CCScrollView.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/components/CCScrollView.js b/cocos2d/core/components/CCScrollView.js index 5e55fdc4ca..ab04c87812 100644 --- a/cocos2d/core/components/CCScrollView.js +++ b/cocos2d/core/components/CCScrollView.js @@ -509,7 +509,7 @@ var ScrollView = cc.Class({ }, /** - * !#en Get the current scroll offset related to scrollview 's top left origin. + * !#en Get the positive offset value corresponds to the content's top left boundary. * !#zh 获取滚动视图相对于左上角原点的当前滚动偏移 * @method getScrollOffset * @return {Vec2} - A Vec2 value indicate the current scroll offset. @@ -526,7 +526,7 @@ var ScrollView = cc.Class({ * !#en Get the maximize available scroll offset * !#zh 获取滚动视图最大可以滚动的偏移量 * @method getMaxScrollOffset - * @return {Ve2c} - A Vec2 value indicate the maximize scroll offset in x and y axis. + * @return {Vec2} - A Vec2 value indicate the maximize scroll offset in x and y axis. */ getMaxScrollOffset: function() { var scrollSize = this.node.getContentSize(); From 54b08a16ad6add82fa640f2b2af8aafd8650ebb4 Mon Sep 17 00:00:00 2001 From: ViusualSJ Date: Tue, 31 May 2016 10:58:03 +0800 Subject: [PATCH 10/17] add resume and fixed setContentSize --- cocos2d/core/videoplayer/CCSGVideoPlayer.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/videoplayer/CCSGVideoPlayer.js b/cocos2d/core/videoplayer/CCSGVideoPlayer.js index 1cf40db0c7..f185cbc857 100644 --- a/cocos2d/core/videoplayer/CCSGVideoPlayer.js +++ b/cocos2d/core/videoplayer/CCSGVideoPlayer.js @@ -57,9 +57,9 @@ _ccsg.VideoPlayer = _ccsg.Node.extend(/** @lends _ccsg.VideoPlayer# */{ this._renderCmd.pause(); }, - //resume: function () { - // this._renderCmd.resume(); - //}, + resume: function () { + this._renderCmd.resume(); + }, stop: function () { this._renderCmd.stop(); @@ -116,6 +116,10 @@ _ccsg.VideoPlayer = _ccsg.Node.extend(/** @lends _ccsg.VideoPlayer# */{ }, setContentSize: function (width, height) { + if (width.width !== undefined && width.height !== undefined) { + height = width.height; + width = width.width; + } _ccsg.Node.prototype.setContentSize.call(this, width, height); this._renderCmd.updateSize(width, height); }, @@ -445,9 +449,9 @@ _ccsg.VideoPlayer.EventType = { } }; - //proto.resume = function () { - // this.play(); - //}; + proto.resume = function () { + this.play(); + }; proto.pause = function () { var video = this._video; From 82caecc33466ed36c28dd2d96d63d51aa972a421 Mon Sep 17 00:00:00 2001 From: ViusualSJ Date: Tue, 31 May 2016 11:43:17 +0800 Subject: [PATCH 11/17] Don't send paused event --- cocos2d/core/videoplayer/CCSGVideoPlayer.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cocos2d/core/videoplayer/CCSGVideoPlayer.js b/cocos2d/core/videoplayer/CCSGVideoPlayer.js index f185cbc857..5181fb1a3c 100644 --- a/cocos2d/core/videoplayer/CCSGVideoPlayer.js +++ b/cocos2d/core/videoplayer/CCSGVideoPlayer.js @@ -57,8 +57,8 @@ _ccsg.VideoPlayer = _ccsg.Node.extend(/** @lends _ccsg.VideoPlayer# */{ this._renderCmd.pause(); }, - resume: function () { - this._renderCmd.resume(); + _resume: function () { + this._renderCmd.play(); }, stop: function () { @@ -248,6 +248,7 @@ _ccsg.VideoPlayer.EventType = { // 有一些浏览器第一次播放视频需要特殊处理,这个标记用来标识是否播放过 this._played = false; this._playing = false; + this._ignorePause = false; }; var proto = _ccsg.VideoPlayer.RenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype); @@ -367,6 +368,9 @@ _ccsg.VideoPlayer.EventType = { node._dispatchEvent(_ccsg.VideoPlayer.EventType.PLAYING); }); video.addEventListener("pause", function(){ + if (self._ignorePause) { + return true; + } node._dispatchEvent(_ccsg.VideoPlayer.EventType.PAUSED); }); video.addEventListener("click", function () { @@ -440,19 +444,13 @@ _ccsg.VideoPlayer.EventType = { setTimeout(function(){ video.play(); self._playing = true; - self._stopped = false; }, 20); }else{ video.play(); this._playing = true; - this._stopped = false; } }; - proto.resume = function () { - this.play(); - }; - proto.pause = function () { var video = this._video; if (!video) return; @@ -463,11 +461,13 @@ _ccsg.VideoPlayer.EventType = { proto.stop = function () { var video = this._video; if (!video) return; + this._ignorePause = true; video.pause(); var node = this._node; setTimeout(function(){ node._dispatchEvent(_ccsg.VideoPlayer.EventType.STOPPED); - }, 0); + this._ignorePause = false; + }.bind(this), 0); // 恢复到视频起始位置 video.currentTime = 0; this._playing = false; From f40d672c5ff3d3e9059da63b42a08691aa5102fb Mon Sep 17 00:00:00 2001 From: ViusualSJ Date: Tue, 31 May 2016 12:04:01 +0800 Subject: [PATCH 12/17] Don't send event when video===null --- cocos2d/core/videoplayer/CCSGVideoPlayer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/videoplayer/CCSGVideoPlayer.js b/cocos2d/core/videoplayer/CCSGVideoPlayer.js index 5181fb1a3c..e16e7da74f 100644 --- a/cocos2d/core/videoplayer/CCSGVideoPlayer.js +++ b/cocos2d/core/videoplayer/CCSGVideoPlayer.js @@ -361,16 +361,16 @@ _ccsg.VideoPlayer.EventType = { var node = this._node, video = this._video, self = this; //binding event video.addEventListener("ended", function(){ + if (self._video !== video) return; this._playing = false; node._dispatchEvent(_ccsg.VideoPlayer.EventType.COMPLETED); }.bind(this)); video.addEventListener("play", function(){ + if (self._video !== video) return; node._dispatchEvent(_ccsg.VideoPlayer.EventType.PLAYING); }); video.addEventListener("pause", function(){ - if (self._ignorePause) { - return true; - } + if (self._ignorePause || self._video !== video) return; node._dispatchEvent(_ccsg.VideoPlayer.EventType.PAUSED); }); video.addEventListener("click", function () { From a8fd1f125ac884deecb3624122d2d766abe7f705 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 31 May 2016 14:06:09 +0800 Subject: [PATCH 13/17] remove auto updateWorldTransform, add updateWorldTransform api for Skeleton --- extensions/spine/SGSkeleton.js | 1 - extensions/spine/Skeleton.js | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/extensions/spine/SGSkeleton.js b/extensions/spine/SGSkeleton.js index b126c189fc..09b2ecfaa1 100644 --- a/extensions/spine/SGSkeleton.js +++ b/extensions/spine/SGSkeleton.js @@ -281,7 +281,6 @@ sp._SGSkeleton = _ccsg.Node.extend({ this.setContentSize(skeletonData.width / cc.director.getContentScaleFactor(), skeletonData.height / cc.director.getContentScaleFactor()); this._skeleton = new spine.Skeleton(skeletonData); - this._skeleton.updateWorldTransform(); this._rootBone = this._skeleton.getRootBone(); this._ownsSkeletonData = ownsSkeletonData; diff --git a/extensions/spine/Skeleton.js b/extensions/spine/Skeleton.js index 3ab49eb2b9..8dadb1ea4e 100644 --- a/extensions/spine/Skeleton.js +++ b/extensions/spine/Skeleton.js @@ -439,6 +439,25 @@ sp.Skeleton = cc.Class({ // RENDERER + /** + * !#en Computes the world SRT from the local SRT for each bone. + * !#zh 重新更新所有骨骼的世界 Transform, + * 当获取 bone 的数值未更新时,即可使用该函数进行更新数值。 + * @method updateWorldTransform + * @example + * var bone = spine.findBone('head'); + * cc.log(bone.worldX); // return 0; + * spine.setToSetupPose(); + * spine.updateWorldTransform(); + * bone = spine.findBone('head'); + * cc.log(bone.worldX); // return -23.12; + */ + updateWorldTransform: function () { + if (this._sgNode) { + this._sgNode.updateWorldTransform(); + } + }, + /** * !#en Sets the bones and slots to the setup pose. * !#zh 还原到起始动作 From 9d47cc05e7b48a2e59ed1847ecc85d003f759928 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 31 May 2016 14:31:13 +0800 Subject: [PATCH 14/17] update updateWorldTransform example for Skeleton --- extensions/spine/Skeleton.js | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/spine/Skeleton.js b/extensions/spine/Skeleton.js index 8dadb1ea4e..339f09aa1f 100644 --- a/extensions/spine/Skeleton.js +++ b/extensions/spine/Skeleton.js @@ -447,7 +447,6 @@ sp.Skeleton = cc.Class({ * @example * var bone = spine.findBone('head'); * cc.log(bone.worldX); // return 0; - * spine.setToSetupPose(); * spine.updateWorldTransform(); * bone = spine.findBone('head'); * cc.log(bone.worldX); // return -23.12; From a9339b83a863768d28f9ac05efff57231d978c8e Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Wed, 1 Jun 2016 11:11:30 +0800 Subject: [PATCH 15/17] fixed collider doc --- cocos2d/core/collider/CCCollisionManager.js | 6 +- cocos2d/core/collider/CCIntersection.js | 102 ++++++++++++-------- 2 files changed, 63 insertions(+), 45 deletions(-) diff --git a/cocos2d/core/collider/CCCollisionManager.js b/cocos2d/core/collider/CCCollisionManager.js index 10b5e8580d..71121113b2 100644 --- a/cocos2d/core/collider/CCCollisionManager.js +++ b/cocos2d/core/collider/CCCollisionManager.js @@ -8,10 +8,10 @@ var CollisionType = Contact.CollisionType; * !#zh * 一个简单的碰撞组件管理类,用于处理节点之间的碰撞组件是否产生了碰撞,并调用相应回调函数。 * - * @class ColliderManager + * @class CollisionManager * @example * - * // Get the collider manager. + * // Get the collision manager. * var manager = cc.director.getCollisionManager(); * * // Enabled the colider manager. @@ -24,7 +24,7 @@ var CollisionType = Contact.CollisionType; * manager.enabledDrawBoundingBox = true; * * - * // Collider callback + * // Collision callback * onCollisionEnter: function (other, self) { * this.node.color = cc.Color.RED; * this.touchingNumber ++; diff --git a/cocos2d/core/collider/CCIntersection.js b/cocos2d/core/collider/CCIntersection.js index 59f33f4da6..4c17276ac1 100644 --- a/cocos2d/core/collider/CCIntersection.js +++ b/cocos2d/core/collider/CCIntersection.js @@ -7,8 +7,10 @@ var Intersection = {}; /** + * !#en Test line and line + * !#zh 测试线段与线段是否相交 * @method lineLine - * @param {Vec2} a1 + * @param {Vec2} a1 * @param {Vec2} a2 * @param {Vec2} b1 * @param {Vec2} b2 @@ -36,6 +38,8 @@ function lineLine ( a1, a2, b1, b2 ) { Intersection.lineLine = lineLine; /** + * !#en Test line and rect + * !#zh 测试线段与矩形是否相交 * @method lineRect * @param {Vec2} a1 * @param {Vec2} a2 @@ -66,6 +70,8 @@ function lineRect ( a1, a2, b ) { Intersection.lineRect = lineRect; /** + * !#en Test line and polygon + * !#zh 测试线段与多边形是否相交 * @method linePolygon * @param {Vec2} a1 * @param {Vec2} a2 @@ -89,6 +95,8 @@ function linePolygon ( a1, a2, b ) { Intersection.linePolygon = linePolygon; /** + * !#en Test rect and rect + * !#zh 测试矩形与矩形是否相交 * @method rectRect * @param {Rect} a * @param {Rect} b @@ -117,6 +125,8 @@ function rectRect ( a, b ) { Intersection.rectRect = rectRect; /** + * !#en Test rect and polygon + * !#zh 测试矩形与多边形是否相交 * @method rectPolygon * @param {Rect} a * @param {[Vec2]} b @@ -167,6 +177,8 @@ function rectPolygon ( a, b ) { Intersection.rectPolygon = rectPolygon; /** + * !#en Test polygon and polygon + * !#zh 测试多边形与多边形是否相交 * @method polygonPolygon * @param {[Vec2]} a * @param {[Vec2]} b @@ -202,7 +214,54 @@ function polygonPolygon ( a, b ) { Intersection.polygonPolygon = polygonPolygon; + /** + * !#en Test circle and circle + * !#zh 测试圆形与圆形是否相交 + * @method circleCircle + * @param {Object} a - Object contains position and radius + * @param {Object} b - Object contains position and radius + * @return {boolean} + */ +function circleCircle (a, b) { + var distance = a.position.sub(b.position).mag(); + return distance < (a.radius + b.radius); +} + +Intersection.circleCircle = circleCircle; + + +/** + * !#en Test polygon and circle + * !#zh 测试矩形与圆形是否相交 + * @method polygonCircle + * @param {[Vec2]} polygon + * @param {Object} circle - Object contains position and radius + * @return {boolean} + */ +function polygonCircle (polygon, circle) { + var position = circle.position; + if (pointInPolygon(position, polygon)) { + return true; + } + + for (var i = 0, l = polygon.length; i < l; i++) { + var start = i === 0 ? polygon[polygon.length - 1] : polygon[i- 1]; + var end = polygon[i]; + + if (pointLineDistance(position, start, end, true) < circle.radius) { + return true; + } + } + + return false; +} + +Intersection.polygonCircle = polygonCircle; + +/** + * !#en Test whether the point is in the polygon + * !#zh 测试一个点是否在一个多边形中 * @method pointInPolygon * @param {Vec2} point * @param {[Vec2]} polygon @@ -230,47 +289,6 @@ function pointInPolygon (point, polygon) { Intersection.pointInPolygon = pointInPolygon; - -/** - * @method circleCircle - * @param {Object} a - Object contains position and radius - * @param {Object} b - Object contains position and radius - * @return {boolean} - */ -function circleCircle (a, b) { - var distance = a.position.sub(b.position).mag(); - return distance < (a.radius + b.radius); -} - -Intersection.circleCircle = circleCircle; - - -/** - * @method polygonCircle - * @param {[Vec2]} polygon - * @param {Object} circle - Object contains position and radius - * @return {boolean} - */ -function polygonCircle (polygon, circle) { - var position = circle.position; - if (pointInPolygon(position, polygon)) { - return true; - } - - for (var i = 0, l = polygon.length; i < l; i++) { - var start = i === 0 ? polygon[polygon.length - 1] : polygon[i- 1]; - var end = polygon[i]; - - if (pointLineDistance(position, start, end, true) < circle.radius) { - return true; - } - } - - return false; -} - -Intersection.polygonCircle = polygonCircle; - /** * !#en Calculate the distance of point to line. * !#zh 计算点到直线的距离。如果这是一条线段并且垂足不在线段内,则会计算点到线段端点的距离。 From d5bafe9aabc0ea956f68ee91307b73189c5d7d02 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Wed, 1 Jun 2016 11:27:01 +0800 Subject: [PATCH 16/17] update CCIntersection doc --- cocos2d/core/collider/CCIntersection.js | 44 ++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/cocos2d/core/collider/CCIntersection.js b/cocos2d/core/collider/CCIntersection.js index 4c17276ac1..ef5fab661b 100644 --- a/cocos2d/core/collider/CCIntersection.js +++ b/cocos2d/core/collider/CCIntersection.js @@ -10,10 +10,10 @@ var Intersection = {}; * !#en Test line and line * !#zh 测试线段与线段是否相交 * @method lineLine - * @param {Vec2} a1 - * @param {Vec2} a2 - * @param {Vec2} b1 - * @param {Vec2} b2 + * @param {Vec2} a1 - The start point of the first line + * @param {Vec2} a2 - The end point of the first line + * @param {Vec2} b1 - The start point of the second line + * @param {Vec2} b2 - The end point of the second line * @return {boolean} */ function lineLine ( a1, a2, b1, b2 ) { @@ -41,9 +41,9 @@ Intersection.lineLine = lineLine; * !#en Test line and rect * !#zh 测试线段与矩形是否相交 * @method lineRect - * @param {Vec2} a1 - * @param {Vec2} a2 - * @param {Vec2} b + * @param {Vec2} a1 - The start point of the line + * @param {Vec2} a2 - The end point of the line + * @param {Rect} b - The rect * @return {boolean} */ function lineRect ( a1, a2, b ) { @@ -73,9 +73,9 @@ Intersection.lineRect = lineRect; * !#en Test line and polygon * !#zh 测试线段与多边形是否相交 * @method linePolygon - * @param {Vec2} a1 - * @param {Vec2} a2 - * @param {[Vec2]} b + * @param {Vec2} a1 - The start point of the line + * @param {Vec2} a2 - The end point of the line + * @param {[Vec2]} b - The polygon, a set of points * @return {boolean} */ function linePolygon ( a1, a2, b ) { @@ -98,8 +98,8 @@ Intersection.linePolygon = linePolygon; * !#en Test rect and rect * !#zh 测试矩形与矩形是否相交 * @method rectRect - * @param {Rect} a - * @param {Rect} b + * @param {Rect} a - The first rect + * @param {Rect} b - The second rect * @return {boolean} */ function rectRect ( a, b ) { @@ -128,8 +128,8 @@ Intersection.rectRect = rectRect; * !#en Test rect and polygon * !#zh 测试矩形与多边形是否相交 * @method rectPolygon - * @param {Rect} a - * @param {[Vec2]} b + * @param {Rect} a - The rect + * @param {[Vec2]} b - The polygon, a set of points * @return {boolean} */ function rectPolygon ( a, b ) { @@ -180,8 +180,8 @@ Intersection.rectPolygon = rectPolygon; * !#en Test polygon and polygon * !#zh 测试多边形与多边形是否相交 * @method polygonPolygon - * @param {[Vec2]} a - * @param {[Vec2]} b + * @param {[Vec2]} a - The first polygon, a set of points + * @param {[Vec2]} b - The second polygon, a set of points * @return {boolean} */ function polygonPolygon ( a, b ) { @@ -235,7 +235,7 @@ Intersection.circleCircle = circleCircle; * !#en Test polygon and circle * !#zh 测试矩形与圆形是否相交 * @method polygonCircle - * @param {[Vec2]} polygon + * @param {[Vec2]} polygon - The Polygon, a set of points * @param {Object} circle - Object contains position and radius * @return {boolean} */ @@ -263,8 +263,8 @@ Intersection.polygonCircle = polygonCircle; * !#en Test whether the point is in the polygon * !#zh 测试一个点是否在一个多边形中 * @method pointInPolygon - * @param {Vec2} point - * @param {[Vec2]} polygon + * @param {Vec2} point - The point + * @param {[Vec2]} polygon - The polygon, a set of points * @return {boolean} */ function pointInPolygon (point, polygon) { @@ -293,9 +293,9 @@ Intersection.pointInPolygon = pointInPolygon; * !#en Calculate the distance of point to line. * !#zh 计算点到直线的距离。如果这是一条线段并且垂足不在线段内,则会计算点到线段端点的距离。 * @method pointLineDistance - * @param {Vec2} point - * @param {Vec2} start - start point of line - * @param {Vec2} end - end point of line + * @param {Vec2} point - The point + * @param {Vec2} start - The start point of line + * @param {Vec2} end - The end point of line * @param {boolean} isSegment - whether this line is a segment * @return {boolean} */ From 90fe87ef1bedbd675532aa00a0df999105df4574 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 1 Jun 2016 14:38:39 +0800 Subject: [PATCH 17/17] fix get spriteFrame name error for jsb --- jsb/jsb-tex-sprite-frame.js | 38 +++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/jsb/jsb-tex-sprite-frame.js b/jsb/jsb-tex-sprite-frame.js index 9e075a41ef..8a3d2adfce 100644 --- a/jsb/jsb-tex-sprite-frame.js +++ b/jsb/jsb-tex-sprite-frame.js @@ -62,13 +62,16 @@ cc.Texture2D.prototype.getPixelHeight = cc.Texture2D.prototype.getPixelsHigh; cc.Class._fastDefine('cc.SpriteFrame', cc.SpriteFrame, []); cc.SpriteFrame.$super = cc.Asset; -cc.js.mixin(cc.SpriteFrame.prototype, cc.EventTarget.prototype); -cc.SpriteFrame.prototype.textureLoaded = function () { +var prototype = cc.SpriteFrame.prototype; + +cc.js.mixin(prototype, cc.EventTarget.prototype); +prototype.textureLoaded = function () { return this.getTexture() !== null; }; // cc.SpriteFrame -cc.SpriteFrame.prototype._ctor = function (filename, rect, rotated, offset, originalSize) { +prototype._ctor = function (filename, rect, rotated, offset, originalSize) { + this._name = ''; if (filename !== undefined) { this.initWithTexture(filename, rect, rotated, offset, originalSize); } else { @@ -76,12 +79,12 @@ cc.SpriteFrame.prototype._ctor = function (filename, rect, rotated, offset, orig } }; -cc.SpriteFrame.prototype._initWithTexture = cc.SpriteFrame.prototype.initWithTexture; -cc.SpriteFrame.prototype.initWithTexture = function (texture, rect, rotated, offset, originalSize) { +prototype._initWithTexture = prototype.initWithTexture; +prototype.initWithTexture = function (texture, rect, rotated, offset, originalSize) { this.setTexture(texture, rect, rotated, offset, originalSize); }; -cc.SpriteFrame.prototype.setTexture = function (textureOrTextureFile, rect, rotated, offset, originalSize) { +prototype.setTexture = function (textureOrTextureFile, rect, rotated, offset, originalSize) { if (rect) { this.setRect(rect); @@ -113,7 +116,7 @@ cc.SpriteFrame.prototype.setTexture = function (textureOrTextureFile, rect, rota return true; }; -cc.SpriteFrame.prototype._refreshTexture = function (texture) { +prototype._refreshTexture = function (texture) { if (this.getTexture() !== texture) { @@ -149,7 +152,7 @@ cc.SpriteFrame.prototype._refreshTexture = function (texture) { } }; -cc.SpriteFrame.prototype._deserialize = function (data, handle) { +prototype._deserialize = function (data, handle) { var rect = data.rect; if (rect) { this.setRect(new cc.Rect(rect[0], rect[1], rect[2], rect[3])); @@ -178,7 +181,7 @@ cc.SpriteFrame.prototype._deserialize = function (data, handle) { handle.result.push(this, '_textureFilenameSetter', textureUuid); } }; -cc.SpriteFrame.prototype._checkRect = function (texture) { +prototype._checkRect = function (texture) { var rect = this.getRect(); var maxX = rect.x, maxY = rect.y; if (this.isRotated()) { @@ -196,16 +199,27 @@ cc.SpriteFrame.prototype._checkRect = function (texture) { cc.error(cc._LogInfos.RectHeight, texture.url); } }; -cc.SpriteFrame.prototype._getTexture = cc.SpriteFrame.prototype.getTexture; -cc.SpriteFrame.prototype.getTexture = function () { + +prototype._getTexture = prototype.getTexture; +prototype.getTexture = function () { var tex = this._getTexture(); this._texture = tex; return tex; }; -cc.js.set(cc.SpriteFrame.prototype, '_textureFilenameSetter', function (url) { + +cc.js.set(prototype, '_textureFilenameSetter', function (url) { this._textureFilename = url; if (url) { var texture = cc.textureCache.addImage(url); this._refreshTexture(texture); } }); + +cc.js.getset(prototype, 'name', + function () { + return this._name; + }, + function (value) { + this._name = value; + } +);