Merge branch 'master' into optimise_canvas_rendering

# Conflicts:
#	cocos2d/clipping-nodes/CCClippingNodeCanvasRenderCmd.js
This commit is contained in:
Huabing.Xu
2016-07-04 09:52:14 +08:00
22 changed files with 768 additions and 1478 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ _p = null;
* @name cc.ENGINE_VERSION
*/
var engineVersion;
engineVersion = '1.1.2-beta.1';
engineVersion = '1.1.2';
window['CocosEngine'] = cc.ENGINE_VERSION = engineVersion;
/**
+7 -6
View File
@@ -528,19 +528,20 @@ cc.Follow = cc.Action.extend({
},
step:function (dt) {
var tempPosX = this._followedNode.x;
var tempPosY = this._followedNode.y;
tempPosX = this._halfScreenSize.x - tempPosX;
tempPosY = this._halfScreenSize.y - tempPosY;
var targetWorldPos = this.target.convertToWorldSpaceAR(cc.Vec2.ZERO);
var followedWorldPos = this._followedNode.convertToWorldSpaceAR(cc.Vec2.ZERO);
// compute the offset between followed and target node
var delta = cc.pSub(targetWorldPos, followedWorldPos);
var tempPos = this.target.parent.convertToNodeSpaceAR(cc.pAdd(delta, this._halfScreenSize));
if (this._boundarySet) {
// whole map fits inside a single screen, no need to modify the position - unless map boundaries are increased
if (this._boundaryFullyCovered)
return;
this.target.setPosition(cc.clampf(tempPosX, this.leftBoundary, this.rightBoundary), cc.clampf(tempPosY, this.bottomBoundary, this.topBoundary));
this.target.setPosition(cc.clampf(tempPos.x, this.leftBoundary, this.rightBoundary), cc.clampf(tempPos.y, this.bottomBoundary, this.topBoundary));
} else {
this.target.setPosition(tempPosX, tempPosY);
this.target.setPosition(tempPos.x, tempPos.y);
}
},
+2 -2
View File
@@ -625,7 +625,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
if (onLaunched) {
onLaunched(null, scene);
}
cc.renderer.clear();
//cc.renderer.clear();
this.emit(cc.Director.EVENT_AFTER_SCENE_LAUNCH, scene);
},
@@ -647,7 +647,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
}
// Delay run / replace scene to the end of the frame
this.once(cc.Director.EVENT_AFTER_DRAW, function () {
this.once(cc.Director.EVENT_AFTER_UPDATE, function () {
this.runSceneImmediate(scene, onBeforeLoadScene, onLaunched);
});
},
@@ -385,6 +385,7 @@ cc.js.getset(CollisionManager.prototype, 'enabledDebugDraw',
cc.director.on(cc.Director.EVENT_AFTER_SCENE_LAUNCH, this.onSceneLaunched, this);
}
else if (!value && this._enabledDebugDraw) {
this._debugDrawer.clear();
cc.director.getScene()._sgNode.removeChild(this._debugDrawer);
cc.director.off(cc.Director.EVENT_AFTER_SCENE_LAUNCH, this.onSceneLaunched, this);
}
+2 -2
View File
@@ -249,8 +249,8 @@ var AudioSource = cc.Class({
*/
rewind: function(){
if ( this.audio ) {
cc.audioEngine.stopEffect(this.audio);
cc.audioEngine.playEffect(this.audio);
this.stop();
this.play();
}
},
+2 -2
View File
@@ -490,11 +490,11 @@ var EditBox = cc.Class({
if(CC_JSB) {
EditBox.prototype.editBoxEditingDidBegin = function (sender) {
this.editBoxEditingDidBegan(sender);
}
};
EditBox.prototype.editBoxEditingDidEnd = function (sender) {
this.editBoxEditingDidEnded(sender);
}
};
}
cc.EditBox = module.exports = EditBox;
+1 -1
View File
@@ -390,7 +390,7 @@ var Widget = cc.Class({
* @default false
*/
isAlignOnce: {
default: false,
default: true,
tooltip: 'i18n:COMPONENT.widget.align_once',
displayName: "AlignOnce"
},
File diff suppressed because it is too large Load Diff
-659
View File
@@ -1,659 +0,0 @@
/****************************************************************************
Copyright (c) 2011-2012 cocos2d-x.org
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
/**
* the DOM object
* @namespace
* @name cc.DOM
*/
cc.DOM = {};
/**
* @function
* @private
* @param node
*/
cc.DOM._addMethods = function (node) {
for (var funcs in cc.DOM.methods) {
node[funcs] = cc.DOM.methods[funcs];
}
// Redefine getter setter
cc.defineGetterSetter(node, "x", node.getPositionX, node.setPositionX);
cc.defineGetterSetter(node, "y", node.getPositionY, node.setPositionY);
cc.defineGetterSetter(node, "width", node._getWidth, node._setWidth);
cc.defineGetterSetter(node, "height", node._getHeight, node._setHeight);
cc.defineGetterSetter(node, "anchorX", node._getAnchorX, node._setAnchorX);
cc.defineGetterSetter(node, "anchorY", node._getAnchorY, node._setAnchorY);
cc.defineGetterSetter(node, "scale", node.getScale, node.setScale);
cc.defineGetterSetter(node, "scaleX", node.getScaleX, node.setScaleX);
cc.defineGetterSetter(node, "scaleY", node.getScaleY, node.setScaleY);
cc.defineGetterSetter(node, "rotation", node.getRotation, node.setRotation);
cc.defineGetterSetter(node, "skewX", node.getSkewX, node.setSkewX);
cc.defineGetterSetter(node, "skewY", node.getSkewY, node.setSkewY);
cc.defineGetterSetter(node, "visible", node.isVisible, node.setVisible);
cc.defineGetterSetter(node, "parent", node.getParent, node.setParent);
cc.defineGetterSetter(node, "opacity", node.getOpacity, node.setOpacity);
};
cc.DOM.methods = /** @lends cc.DOM# */{
/**
* Replace the set position of ccNode
* @param {cc.Vec2|Number} x
* @param {Number} y
*/
setPosition:function (x, y) {
if (y === undefined) {
this._position.x = x.x;
this._position.y = x.y;
} else {
this._position.x = x;
this._position.y = y;
}
this.setNodeDirty();
this.dom.translates(this._position.x, -this._position.y);
},
/**
* replace set Position Y of ccNode
* @param {Number} y
*/
setPositionY:function (y) {
this._position.y = y;
this.setNodeDirty();
this.dom.translates(this._position.x, -this._position.y);
},
/**
* replace set Position X of ccNode
* @param {Number} x
*/
setPositionX:function (x) {
this._position.x = x;
this.setNodeDirty();
this.dom.translates(this._position.x, -this._position.y);
},
/**
* replace set Scale of ccNode
* @param {object|Number} scale
* @param {Number} scaleY
*/
setScale:function (scale, scaleY) {
//save dirty region when before change
//this._addDirtyRegionToDirector(this.getBoundingBoxToWorld());
this._scaleX = scale;
this._scaleY = scaleY || scale;
//save dirty region when after changed
//this._addDirtyRegionToDirector(this.getBoundingBoxToWorld());
this.setNodeDirty();
this.dom.resize(this._scaleX, this._scaleY);
},
/**
* replace set Scale X of ccNode
* @param {Number} x
*/
setScaleX:function (x) {
this._scaleX = x;
this.setNodeDirty();
this.dom.resize(this._scaleX, this._scaleY);
},
/**
* replace set Scale Y of ccNode
* @param {Number} y
*/
setScaleY:function (y) {
this._scaleY = y;
this.setNodeDirty();
this.dom.resize(this._scaleX, this._scaleY);
},
/**
* replace set anchorpoint of ccNode
* @param {cc.Vec2|Number} point The anchor point of node or The anchor point.x of node.
* @param {Number} [y] The anchor point.y of node.
*/
setAnchorPoint:function (point, y) {
var cmd = this._renderCmd;
var locAnchorPoint = this._anchorPoint;
if (y === undefined) {
locAnchorPoint.x = point.x;
locAnchorPoint.y = point.y;
} else {
locAnchorPoint.x = point;
locAnchorPoint.y = y;
}
var locAPP = cmd._anchorPointInPoints, locSize = this._contentSize;
locAPP.x = locSize.width * locAnchorPoint.x;
locAPP.y = locSize.height * locAnchorPoint.y;
this.dom.style[cc.$.pfx + 'TransformOrigin'] = '' + locAPP.x + 'px ' + -locAPP.y + 'px';
if (this.ignoreAnchor) {
this.dom.style.marginLeft = 0;
this.dom.style.marginBottom = 0;
} else {
this.dom.style.marginLeft = (this.isToggler) ? 0 : -locAPP.x + 'px';
this.dom.style.marginBottom = -locAPP.y + 'px';
}
this.setNodeDirty();
},
/**
* replace set anchorpoint x of ccNode
* @param {Number} x The anchor x of node.
*/
_setAnchorX:function (x) {
var locAnchorPoint = this._anchorPoint;
var cmd = this._renderCmd;
if (x === locAnchorPoint.x)
return;
locAnchorPoint.x = x;
var locAPP = cmd._anchorPointInPoints, locSize = this._contentSize;
locAPP.x = locSize.width * locAnchorPoint.x;
this.dom.style[cc.$.pfx + 'TransformOrigin'] = '' + locAPP.x + 'px ' + -locAPP.y + 'px';
if (this.ignoreAnchor) {
this.dom.style.marginLeft = 0;
this.dom.style.marginBottom = 0;
} else {
this.dom.style.marginLeft = (this.isToggler) ? 0 : -locAPP.x + 'px';
}
this.setNodeDirty();
},
/**
* replace set anchorpoint y of ccNode
* @param {Number} y The anchor y of node.
*/
_setAnchorY:function (y) {
var locAnchorPoint = this._anchorPoint;
var cmd = this._renderCmd;
if (y === locAnchorPoint.y)
return;
locAnchorPoint.y = y;
var locAPP = cmd._anchorPointInPoints, locSize = this._contentSize;
locAPP.y = locSize.height * locAnchorPoint.y;
this.dom.style[cc.$.pfx + 'TransformOrigin'] = '' + locAPP.x + 'px ' + -locAPP.y + 'px';
if (this.ignoreAnchor) {
this.dom.style.marginLeft = 0;
this.dom.style.marginBottom = 0;
} else {
this.dom.style.marginBottom = -locAPP.y + 'px';
}
this.setNodeDirty();
},
/**
* replace set ContentSize of ccNode
* @param {cc.Size|Number} size The untransformed size of the node or The untransformed size's width of the node.
* @param {Number} [height] The untransformed size's height of the node.
*/
setContentSize:function (size, height) {
var cmd = this._renderCmd;
var locContentSize = this._contentSize;
if (height === undefined) {
locContentSize.width = size.width;
locContentSize.height = size.height;
} else {
locContentSize.width = size;
locContentSize.height = height;
}
var locAPP = cmd._anchorPointInPoints, locAnchorPoint = this._anchorPoint;
locAPP.x = locContentSize.width * locAnchorPoint.x;
locAPP.y = locContentSize.height * locAnchorPoint.y;
this.dom.width = locContentSize.width;
this.dom.height = locContentSize.height;
this.setAnchorPoint(this.getAnchorPoint());
if (this.canvas) {
this.canvas.width = locContentSize.width;
this.canvas.height = locContentSize.height;
}
this.setNodeDirty();
// this.redraw();
},
/**
* replace set width of ccNode
* @param {Number} width The untransformed size's width of the node.
*/
_setWidth:function (width) {
var locContentSize = this._contentSize;
var cmd = this._renderCmd;
if (width === locContentSize.width)
return;
locContentSize.width = width;
var locAPP = cmd._anchorPointInPoints, locAnchorPoint = this._anchorPoint;
locAPP.x = locContentSize.width * locAnchorPoint.x;
this.dom.width = locContentSize.width;
this.anchorX = locAnchorPoint.x;
if (this.canvas) {
this.canvas.width = locContentSize.width;
}
this.setNodeDirty();
// this.redraw();
},
/**
* replace set height of ccNode
* @param {Number} height The untransformed size's height of the node.
*/
_setHeight:function (height) {
var locContentSize = this._contentSize;
var cmd = this._renderCmd;
if (height === locContentSize.height)
return;
locContentSize.height = height;
var locAPP = cmd._anchorPointInPoints, locAnchorPoint = this._anchorPoint;
locAPP.y = locContentSize.height * locAnchorPoint.y;
this.dom.height = locContentSize.height;
this.anchorY = locAnchorPoint.y;
if (this.canvas) {
this.canvas.height = locContentSize.height;
}
this.setNodeDirty();
// this.redraw();
},
/**
* replace set Rotation of ccNode
* @param {Number} newRotation
*/
setRotation:function (newRotation) {
if (this._rotation === newRotation)
return;
this._rotationX = this._rotationY = newRotation;
this.setNodeDirty();
this.dom.rotate(newRotation);
},
/**
* replace set SkewX of ccNode
* @param {Number} x
*/
setSkewX:function (x) {
this._skewX = x;
this.setNodeDirty();
this.dom.setSkew(this._skewX, this._skewY);
},
/**
* replace set SkewY of ccNode
* @param {Number} y
*/
setSkewY:function (y) {
this._skewY = y;
this.setNodeDirty();
this.dom.setSkew(this._skewX, this._skewY);
},
/**
* replace set Visible of ccNode
* @param {Boolean} x
*/
setVisible:function (x) {
_ccsg.Node.prototype.setVisible.call(this, x);
this._visible = x;
this.setNodeDirty();
if (this.dom)
this.dom.style.display = (x) ? 'block' : 'none';
},
_setLocalZOrder:function (z) {
this._localZOrder = z
this.setNodeDirty();
if (this.dom)
this.dom.zIndex = z;
},
/**
* replace set Parent of ccNode
* @param {_ccsg.Node} p
*/
setParent:function (p) {
this._parent = p;
if (p !== null) {
p.setAnchorPoint(p.getAnchorPoint());
this.setNodeDirty();
cc.DOM.parentDOM(this);
}
},
/**
* replace resume Schedule and actions of ccNode
*/
resume:function () {
this.getScheduler().resumeTarget(this);
this.getActionManager().resumeTarget(this);
cc.eventManager.resumeTarget(this);
//if dom does not have parent, but node has no parent and its running
if (this.dom && !this.dom.parentNode) {
if (!this.getParent()) {
if(this.dom.id === ""){
cc.DOM._createEGLViewDiv(this);
}else{
this.dom.appendTo(cc.container);
}
} else {
cc.DOM.parentDOM(this);
}
}
if (this.dom)
this.dom.style.visibility = "visible";
},
/**
* replace pause Schedule and Actions of ccNode
*/
pause:function () {
this.getScheduler().pauseTarget(this);
this.getActionManager().pauseTarget(this);
cc.eventManager.pauseTarget(this);
if (this.dom) {
this.dom.style.visibility = 'hidden';
}
},
/**
* replace clean up of ccNode
*/
cleanup:function () {
// actions
this.stopAllActions();
this.unscheduleAllCallbacks();
// timers
this._arrayMakeObjectsPerformSelector(this._children, _ccsg.Node._stateCallbackType.cleanup);
if (this.dom) {
this.dom.remove();
}
},
/**
* replace remove from parent and clean up of ccNode
*/
removeFromParentAndCleanup:function () {
this.dom.remove();
},
setOpacity:function (o) {
_ccsg.Node.prototype.setOpacity.call(this, o);
this._opacity = o;
this.dom.style.opacity = o / 255;
},
/**
* refresh/updates the DOM element
*/
redraw:function () {
if (this.isSprite) {
var tmp = this._children;
this._children = [];
_ccsg.Sprite.prototype.visit.call(this, this.ctx);
this._children = tmp;
}
else {
_ccsg.Sprite.prototype.visit.call(this, this.ctx);
}
}
};
cc.DOM._resetEGLViewDiv = function(){
var div = cc.$("#EGLViewDiv");
if(div){
var view = cc.view;
var designSize = view.getDesignResolutionSize();
var viewPortRect = view.getViewPortRect();
var screenSize = view.getFrameSize();
var pixelRatio = view.getDevicePixelRatio();
var designSizeWidth = designSize.width, designSizeHeight = designSize.height;
if((designSize.width === 0) && (designSize.height === 0)){
designSizeWidth = screenSize.width;
designSizeHeight = screenSize.height;
}
var viewPortWidth = viewPortRect.width/pixelRatio;
if((viewPortRect.width === 0) && (viewPortRect.height === 0)){
viewPortWidth = screenSize.width;
}
div.style.position = 'absolute';
//x.dom.style.display='block';
div.style.width = designSizeWidth + "px";
div.style.maxHeight = designSizeHeight + "px";
div.style.margin = 0;
div.resize(view.getScaleX()/pixelRatio, view.getScaleY()/pixelRatio);
if (view.getResolutionPolicy() === view._rpNoBorder) {
div.style.left = (view.getFrameSize().width - designSizeWidth)/2 + "px";
div.style.bottom = (view.getFrameSize().height - designSizeHeight*view.getScaleY()/pixelRatio)/2 + "px";
}
else {
div.style.left = (designSizeWidth*view.getScaleX()/pixelRatio - designSizeWidth) / 2 + "px";
div.style.bottom = "0px";
}
}
};
/**
* @function
* @private
* @param x
* @return {Boolean}
*/
cc.DOM.parentDOM = function (x) {
var p = x.getParent();
//if has parent, parent need to have dom too
if (!p || !x.dom)
return false;
if (!p.dom) {
cc.DOM.placeHolder(p);
p.setParent = cc.DOM.methods.setParent;
}
//if parent have dom, attach self to parent
x.dom.appendTo(p.dom);
p.setAnchorPoint(p.getAnchorPoint());
if (p.getParent()) {
cc.DOM.parentDOM(p);
} else {
//parent has no more parent, if its running, then add it to the container
if (p.isRunning()) {
//find EGLView div
var eglViewDiv = cc.$("#EGLViewDiv");
if (eglViewDiv) {
p.dom.appendTo(eglViewDiv);
} else {
cc.DOM._createEGLViewDiv(p);
}
}
}
return true;
};
cc.DOM._createEGLViewDiv = function(p){
var div = cc.$("#EGLViewDiv");
if(!div){
div = cc.$new("div");
div.id = "EGLViewDiv";
}
var view = cc.view;
var designSize = view.getDesignResolutionSize();
var viewPortRect = view.getViewPortRect();
var screenSize = view.getFrameSize();
var pixelRatio = view.getDevicePixelRatio();
var designSizeWidth = designSize.width, designSizeHeight = designSize.height;
if ((designSize.width === 0) && (designSize.height === 0)) {
designSizeWidth = screenSize.width;
designSizeHeight = screenSize.height;
}
var viewPortWidth = viewPortRect.width/pixelRatio;
if ((viewPortRect.width === 0) && (viewPortRect.height === 0)) {
viewPortWidth = screenSize.width;
}
div.style.position = 'absolute';
//x.dom.style.display='block';
div.style.width = designSizeWidth + "px";
div.style.maxHeight = designSizeHeight + "px";
div.style.margin = 0;
div.resize(view.getScaleX()/pixelRatio, view.getScaleY()/pixelRatio);
if (view.getResolutionPolicy() === view._rpNoBorder) {
div.style.left = (screenSize.width - designSizeWidth)/2 + "px";
div.style.bottom = (screenSize.height - designSizeHeight*view.getScaleY()/pixelRatio)/2 + "px";
}
else {
div.style.left = (designSizeWidth*view.getScaleX()/pixelRatio - designSizeWidth) / 2 + "px";
div.style.bottom = "0px";
}
p.dom.appendTo(div);
div.appendTo(cc.container);
};
/**
* @function
* @private
* @param x
*/
cc.DOM.setTransform = function (x) {
if (x.ctx) {
x.ctx.translate(x.getAnchorPointInPoints().x, x.getAnchorPointInPoints().y);
if (x.isSprite) {
var tmp = x._children;
x._children = [];
_ccsg.Sprite.prototype.visit.call(x);
x._children = tmp;
}
else {
_ccsg.Sprite.prototype.visit.call(x);
}
}
if (x.dom) {
x.dom.position.x = x.getPositionX();
x.dom.position.y = -x.getPositionY();
x.dom.rotation = x.getRotation();
x.dom.scale = {x:x.getScaleX(), y:x.getScaleY()};
x.dom.skew = {x:x.getSkewX(), y:x.getSkewY()};
if (x.setAnchorPoint)
x.setAnchorPoint(x.getAnchorPoint());
x.dom.transforms();
}
};
/**
* @function
* @private
* @param x
*/
cc.DOM.forSprite = function (x) {
x.dom = cc.$new('div');
x.canvas = cc.$new('canvas');
var locContentSize = x.getContentSize();
x.canvas.width = locContentSize.width;
x.canvas.height = locContentSize.height;
x.dom.style.position = 'absolute';
x.dom.style.bottom = 0;
x.ctx = x.canvas.getContext('2d');
x.dom.appendChild(x.canvas);
if (x.getParent()) {
cc.DOM.parentDOM(x);
}
x.isSprite = true;
};
/**
* This creates divs for parent Nodes that are related to the current node
* @function
* @private
* @param x
*/
cc.DOM.placeHolder = function (x) {
//creating a placeholder dom to simulate other ccNode in the hierachy
x.dom = cc.$new('div');
// x.placeholder = true;
x.dom.style.position = 'absolute';
x.dom.style.bottom = 0;
//x.dom.style.display='block';
x.dom.style.width = (x.getContentSize().width || cc.director.getWinSize().width) + "px";
x.dom.style.maxHeight = (x.getContentSize().height || cc.director.getWinSize().height) + "px";
x.dom.style.margin = 0;
cc.DOM.setTransform(x);
x.dom.transforms();
cc.DOM._addMethods(x);
//x.dom.style.border = 'red 1px dotted';
};
/**
* Converts _ccsg.Sprite or cc.MenuItem to DOM elements <br/>
* It currently only supports _ccsg.Sprite and cc.MenuItem
* @function
* @param {_ccsg.Sprite|cc.MenuItem|Array} nodeObject
* @example
* // example
* cc.DOM.convert(Sprite1, Sprite2, Menuitem);
*
* var myDOMElements = [Sprite1, Sprite2, MenuItem];
* cc.DOM.convert(myDOMElements);
*/
cc.DOM.convert = function (nodeObject) {
//if passing by list, make it an array
if (arguments.length > 1) {
cc.DOM.convert(arguments);
return;
} else if (arguments.length === 1 && !arguments[0].length) {
cc.DOM.convert([arguments[0]]);
return;
}
var args = arguments[0];
for (var i = 0; i < args.length; i++) {
//first check if its sprite
if (args[i] instanceof _ccsg.Sprite) {
// create a canvas
if (!args[i].dom)
cc.DOM.forSprite(args[i]);
} else {
cc.log('DOM converter only supports sprite and menuitems yet');
}
cc.DOM._addMethods(args[i]);
args[i].visit = function () {
};
args[i].transform = function () {
};
cc.DOM.setTransform(args[i]);
args[i].setVisible(args[i].isVisible());
}
};
@@ -113,6 +113,6 @@ function downloadBinary (url, callback) {
};
}
xhr.send(null);
};
}
module.exports = downloadBinary;
+5 -68
View File
@@ -26,6 +26,10 @@ var JS = require('../platform/js');
var Path = require('../utils/CCPath');
var Pipeline = require('./pipeline');
var PackDownloader = require('./pack-downloader');
// var downloadBinary = require('./binary-downloader');
var downloadText = require('./text-downloader');
var urlAppendTimestamp = require('./utils').urlAppendTimestamp;
var downloadAudio;
if (!CC_EDITOR || !Editor.isMainProcess) {
@@ -34,32 +38,6 @@ if (!CC_EDITOR || !Editor.isMainProcess) {
else {
downloadAudio = null;
}
// var downloadBinary = require('binary-downloader');
function isUrlCrossOrigin (url) {
if (!url) {
cc.log('invalid URL');
return false;
}
var startIndex = url.indexOf('://');
if (startIndex === -1)
return false;
var endIndex = url.indexOf('/', startIndex + 3);
var urlOrigin = (endIndex === -1) ? url : url.substring(0, endIndex);
return urlOrigin !== location.origin;
}
var _noCacheRex = /\?/;
function urlAppendTimestamp (url) {
if (cc.game.config['noCache'] && typeof url === 'string') {
if(_noCacheRex.test(url))
url += '&_t=' + (new Date() - 0);
else
url += '?_t=' + (new Date() - 0);
}
return url;
}
function downloadScript (item, callback, isAsync) {
var url = item.url,
@@ -84,47 +62,6 @@ function downloadScript (item, callback, isAsync) {
d.body.appendChild(s);
}
function downloadText (item, callback) {
var url = item.url,
xhr = Pipeline.getXMLHttpRequest(),
errInfo = 'Load ' + url + ' failed!',
navigator = window.navigator;
url = urlAppendTimestamp(url);
xhr.open('GET', url, true);
if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
// IE-specific logic here
xhr.setRequestHeader('Accept-Charset', 'utf-8');
xhr.onreadystatechange = function () {
if(xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
callback(null, xhr.responseText);
}
else {
callback({status:xhr.status, errorMessage:errInfo});
}
}
};
} else {
if (xhr.overrideMimeType) xhr.overrideMimeType('text\/plain; charset=utf-8');
xhr.onload = function () {
if(xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
callback(null, xhr.responseText);
}
else {
callback({status:xhr.status, errorMessage:errInfo});
}
}
};
xhr.onerror = function(){
callback({status:xhr.status, errorMessage:errInfo});
};
}
xhr.send(null);
}
function downloadTextSync (item) {
var url = item.url;
var xhr = Pipeline.getXMLHttpRequest();
@@ -387,7 +324,7 @@ JS.mixin(Downloader.prototype, {
* @param {Object} extMap Custom supported types with corresponded handler
*/
addHandlers: function (extMap) {
this.extMap = JS.mixin(this.extMap, extMap);
JS.mixin(this.extMap, extMap);
},
handle: function (item, callback) {
+12 -8
View File
@@ -24,6 +24,7 @@
****************************************************************************/
var JsonUnpacker = require('./json-unpacker');
var downloadText = require('./text-downloader');
// {assetUuid: packUuid}
var uuidToPack = {};
@@ -55,7 +56,7 @@ module.exports = {
_loadNewPack: function (uuid, packUuid, callback) {
var packUrl = cc.AssetLibrary.getImportedDir(packUuid) + '/' + packUuid + '.json';
cc.loader.load(packUrl, function (err, packJson) {
downloadText({ url: packUrl }, function (err, packJson) {
if (err) {
cc.error('Failed to download package for ' + uuid);
return callback(err);
@@ -96,13 +97,16 @@ module.exports = {
var unpacker = globalUnpackers[packUuid];
if (unpacker) {
var json = unpacker.retrieve(uuid);
if (json) {
callback(null, json);
}
else {
error(callback, uuid, packUuid);
}
// ensure async
setTimeout(function () {
var json = unpacker.retrieve(uuid);
if (json) {
callback(null, json);
}
else {
error(callback, uuid, packUuid);
}
}, 0);
}
else {
this._loadNewPack(uuid, packUuid, callback);
@@ -0,0 +1,58 @@
if (CC_JSB) {
module.exports = function (item, callback) {
var url = item.url;
var result = jsb.fileUtils.getStringFromFile(url);
if (typeof result === 'string' && result) {
callback(null, result);
}
else {
callback(new Error('Download text failed: ' + url));
}
}
}
else {
var Pipeline = require('./pipeline');
var urlAppendTimestamp = require('./utils').urlAppendTimestamp;
module.exports = function (item, callback) {
var url = item.url,
xhr = Pipeline.getXMLHttpRequest(),
errInfo = 'Load ' + url + ' failed!',
navigator = window.navigator;
url = urlAppendTimestamp(url);
xhr.open('GET', url, true);
if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
// IE-specific logic here
xhr.setRequestHeader('Accept-Charset', 'utf-8');
xhr.onreadystatechange = function () {
if(xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
callback(null, xhr.responseText);
}
else {
callback({status:xhr.status, errorMessage:errInfo});
}
}
};
} else {
if (xhr.overrideMimeType) xhr.overrideMimeType('text\/plain; charset=utf-8');
xhr.onload = function () {
if(xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
callback(null, xhr.responseText);
}
else {
callback({status:xhr.status, errorMessage:errInfo});
}
}
};
xhr.onerror = function(){
callback({status:xhr.status, errorMessage:errInfo});
};
}
xhr.send(null);
};
}
+26
View File
@@ -0,0 +1,26 @@
var _noCacheRex = /\?/;
module.exports = {
//isUrlCrossOrigin: function (url) {
// if (!url) {
// cc.log('invalid URL');
// return false;
// }
// var startIndex = url.indexOf('://');
// if (startIndex === -1)
// return false;
//
// var endIndex = url.indexOf('/', startIndex + 3);
// var urlOrigin = (endIndex === -1) ? url : url.substring(0, endIndex);
// return urlOrigin !== location.origin;
//},
urlAppendTimestamp: function (url) {
if (cc.game.config['noCache'] && typeof url === 'string') {
if(_noCacheRex.test(url))
url += '&_t=' + (new Date() - 0);
else
url += '?_t=' + (new Date() - 0);
}
return url;
}
};
+7
View File
@@ -772,6 +772,13 @@ else {
__audioSupport = { ONLY_ONE: false, WEB_AUDIO: supportWebAudio, DELAY_CREATE_CTX: false };
if (sys.os === sys.OS_IOS) {
// IOS no event that used to parse completed callback
// this time is not complete, can not play
//
__audioSupport.USE_LOADER_EVENT = 'loadedmetadata';
}
if (sys.browserType === sys.BROWSER_TYPE_FIREFOX) {
__audioSupport.DELAY_CREATE_CTX = true;
__audioSupport.USE_LOADER_EVENT = 'canplay';
+4 -2
View File
@@ -202,8 +202,10 @@ cc.clone = function (obj) {
for (var key in obj) {
var copy = obj[key];
// Beware that typeof null == "object" !
if (((typeof copy) === "object") && copy &&
!(copy instanceof _ccsg.Node) && !(copy instanceof HTMLElement)) {
if (typeof copy === "object" &&
copy &&
!(copy instanceof _ccsg.Node) &&
(CC_JSB || !(copy instanceof HTMLElement))) {
newObj[key] = cc.clone(copy);
} else {
newObj[key] = copy;
+15 -5
View File
@@ -217,10 +217,13 @@ var _Deserializer = (function () {
var _dereference = function (self) {
// 这里不采用遍历反序列化结果的方式,因为反序列化的结果如果引用到复杂的外部库,很容易堆栈溢出。
var deserializedList = self.deserializedList;
var idPropList = self._idPropList;
var idList = self._idList;
var idObjList = self._idObjList;
for (var i = 0, len = self._idList.length; i < len; i++) {
var propName = self._idPropList[i];
var id = self._idList[i];
self._idObjList[i][propName] = deserializedList[id];
var propName = idPropList[i];
var id = idList[i];
idObjList[i][propName] = deserializedList[id];
}
};
@@ -387,8 +390,8 @@ var _Deserializer = (function () {
}
}
if (props[props.length - 1] === '_$erialized') {
// save original serialized data
obj._$erialized = serialized;
// deep copy original serialized data
obj._$erialized = JSON.parse(JSON.stringify(serialized));
// parse the serialized data as primitive javascript object, so its __id__ will be dereferenced
_deserializePrimitiveObject(self, obj._$erialized, serialized);
}
@@ -523,6 +526,8 @@ cc.deserialize = function (data, result, options) {
data = JSON.parse(data);
}
//var oldJson = JSON.stringify(data, null, 2);
if (createAssetRefs && !result) {
result = new Details();
}
@@ -534,6 +539,11 @@ cc.deserialize = function (data, result, options) {
result.assignAssetsBy(Editor.serialize.asAsset);
}
//var afterJson = JSON.stringify(data, null, 2);
//if (oldJson !== afterJson) {
// throw new Error('JSON SHOULD not changed');
//}
return deserializer.deserializedData;
};
@@ -1,3 +1,6 @@
// frame : The exactly time in second.
// func : Callback function name
// params : Callback parameters
[
{ frame: 0, func: 'onAnimationEvent1', params:['param-1', 'param-2'] },
{ frame: 2, func: 'onAnimationEvent3', params:['param-1', 'param-2'] },
+38 -3
View File
@@ -38,8 +38,9 @@
* !#zh
* cc.NodePool 是用于管理节点对象的对象缓存池。<br/>
* 它可以帮助您提高游戏性能,适用于优化对象的反复创建和销毁<br/>
* 以前 cocos2d-x 中的 cc.pool 和新的节点事件注册系统不兼容,因此请使用 cc.NodePool 来代替。
*
* 建议为每种节点分别实例化一个缓冲池,这里的种类对应于游戏中的节点设计,一个 prefab 相当于一个种类的节点。<br/>
* 新的 NodePool 需要实例化之后才能使用,每种不同的节点对象池需要一个不同的对象池实例,这里的种类对应于游戏中的节点设计,一个 prefab 相当于一个种类的节点。<br/>
* 在创建缓冲池时,可以传入一个包含 unuse, reuse 函数的组件类型用于节点的回收和复用逻辑。<br/>
*
* 一些常见的用例是:<br/>
@@ -47,8 +48,23 @@
* 2.糖果粉碎传奇中的木块(频繁创建)。
* 等等....
* @class NodePool
* @param {Function|String} poolHandlerComp The constructor or the class name of the component to control the unuse/reuse logic.
* @constructor
*/
/**
* !#en
* Constructor for creating a pool for a specific node template (usually a prefab). You can pass a component (type or name) argument for handling event for reusing and recycling node.
* !#zh
* 使用构造函数来创建一个节点专用的对象池,您可以传递一个组件类型或名称,用于处理节点回收和复用时的事件逻辑。
* @param {Function|String} poolHandlerComp !#en The constructor or the class name of the component to control the unuse/reuse logic. !#zh 处理节点回收和复用事件逻辑的组件类型或名称。
* @method NodePool
* @example
* properties: {
* template: cc.Prefab
* },
* onLoad () {
// MyTemplateHandler is a component with 'unuse' and 'reuse' to handle events when node is reused or recycled.
* this.myPool = new cc.NodePool('MyTemplateHandler');
* }
*/
cc.NodePool = function (poolHandlerComp) {
/**
@@ -72,6 +88,19 @@ cc.NodePool.prototype = {
return this._pool.length;
},
/**
* !#en Destroy all cached nodes in the pool
* !#zh 销毁对象池中缓存的所有节点
* @method clear
*/
clear: function () {
var count = this._pool.length;
for (var i = 0; i < count; ++i) {
this._pool[i].destroy();
}
this._pool.length = 0;
},
/**
* !#en Put a new Node into the pool.
* It will automatically remove the node from its parent without cleanup.
@@ -80,6 +109,9 @@ cc.NodePool.prototype = {
* 这个函数会自动将目标节点从父节点上移除,但是不会进行 cleanup 操作。
* 这个函数会调用 poolHandlerComp 的 unuse 函数,如果组件和函数都存在的话。
* @method put
* @example
* let myNode = cc.instantiate(this.template);
* this.myPool.put(myNode);
*/
put: function (obj) {
if (obj && this._pool.indexOf(obj) === -1) {
@@ -102,7 +134,10 @@ cc.NodePool.prototype = {
* !#zh 获取对象池中的对象,如果对象池没有可用对象,则返回空。
* 这个函数会调用 poolHandlerComp 的 reuse 函数,如果组件和函数都存在的话。
* @method get
* @param {any} params - !#en Params to pass to 'reuse' method in poolHandlerComp !#zh 向 poolHandlerComp 中的 'reuse' 函数传递的参数
* @return {Object|null}
* @example
* let newNode = this.myPool.get();
*/
get: function () {
var last = this._pool.length-1;
+7
View File
@@ -116,6 +116,13 @@ cc.follow = function (followedNode, rect) {
return new cc.Follow(followedNode._sgNode, rect);
};
cc.Follow.prototype.update = function(dt) {
var target = this.getTarget();
if (target._owner) {
target._owner.setPosition(target.getPosition());
}
};
// Special call func
cc.callFunc = function (selector, selectorTarget, data) {
var callback = function (sender, data) {
+1 -1
View File
@@ -203,7 +203,7 @@ cc.js.mixin(cc.director, {
}
// Delay run / replace scene to the end of the frame
this.once(cc.Director.EVENT_AFTER_DRAW, function () {
this.once(cc.Director.EVENT_AFTER_UPDATE, function () {
this.runSceneImmediate(scene, onBeforeLoadScene, onLaunched);
});
},
-30
View File
@@ -36,18 +36,6 @@ function downloadScript (item, callback) {
callback(null, url);
}
function downloadText (item, callback) {
var url = item.url;
var result = jsb.fileUtils.getStringFromFile(url);
if (typeof result === 'string' && result) {
callback(null, result);
}
else {
callback(new Error('Download text failed: ' + url));
}
}
function downloadAudio (item, callback) {
callback(null, item.url);
}
@@ -75,22 +63,6 @@ cc.loader.addDownloadHandlers({
'mp4' : downloadAudio,
'm4a' : downloadAudio,
// Txt
'txt' : downloadText,
'xml' : downloadText,
'vsh' : downloadText,
'fsh' : downloadText,
'atlas' : downloadText,
'tmx' : downloadText,
'tsx' : downloadText,
'json' : downloadText,
'ExportJson' : downloadText,
'plist' : downloadText,
'fnt' : downloadText,
// Font
'font' : empty,
'eot' : empty,
@@ -98,8 +70,6 @@ cc.loader.addDownloadHandlers({
'woff' : empty,
'svg' : empty,
'ttc' : empty,
'default' : downloadText
});