diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 00000000000..ede3315710d
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,13 @@
+{
+ "files.exclude": {
+ ".git": true,
+ "node_modules": true,
+ ".github": true
+ },
+ "search.exclude": {
+ ".git": true,
+ "node_modules": true,
+ ".github": true,
+ "bin": true
+ }
+}
\ No newline at end of file
diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js
index 3bce7e978f1..4aaf8655f2b 100644
--- a/cocos2d/core/CCDirector.js
+++ b/cocos2d/core/CCDirector.js
@@ -448,9 +448,9 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
// They are needed in case the director is run again
if (this._runningScene) {
- this._runningScene.performRecursive(_ccsg.Node.performType.onExitTransitionDidStart);
- this._runningScene.performRecursive(_ccsg.Node.performType.onExit);
- this._runningScene.performRecursive(_ccsg.Node.performType.cleanup);
+ // this._runningScene.performRecursive(_ccsg.Node.performType.onExitTransitionDidStart);
+ // this._runningScene.performRecursive(_ccsg.Node.performType.onExit);
+ // this._runningScene.performRecursive(_ccsg.Node.performType.cleanup);
cc.renderer.clearRenderCommands();
}
@@ -583,12 +583,9 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
}
this.emit(cc.Director.EVENT_BEFORE_SCENE_LAUNCH, scene);
- var sgScene = scene;
-
// Run an Entity Scene
if (scene instanceof cc.Scene) {
this._scene = scene;
- sgScene = scene._sgNode;
// Re-attach or replace persist nodes
CC_BUILD && CC_DEBUG && console.time('AttachPersist');
@@ -614,15 +611,15 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
// Run or replace rendering scene
if ( !this._runningScene ) {
//start scene
- this.pushScene(sgScene);
+ this.pushScene(scene);
this.startAnimation();
}
else {
//replace scene
var i = this._scenesStack.length;
- this._scenesStack[Math.max(i - 1, 0)] = sgScene;
+ this._scenesStack[Math.max(i - 1, 0)] = scene;
this._sendCleanupToScene = true;
- this._nextScene = sgScene;
+ this._nextScene = scene;
}
if (this._nextScene) {
@@ -890,7 +887,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
* @method setClearColor
* @param {Color} clearColor
*/
- setClearColor: null,
+ setClearColor: function () {
+ },
/**
* Sets the default values based on the CCConfiguration info
*/
@@ -910,34 +908,34 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
* Starts the registered next scene
*/
setNextScene: function () {
- var runningIsTransition = false, newIsTransition = false;
- if (cc.TransitionScene) {
- runningIsTransition = this._runningScene ? this._runningScene instanceof cc.TransitionScene : false;
- newIsTransition = this._nextScene ? this._nextScene instanceof cc.TransitionScene : false;
- }
-
- // If it is not a transition, call onExit/cleanup
- if (!newIsTransition) {
- var locRunningScene = this._runningScene;
- if (locRunningScene) {
- locRunningScene.performRecursive(_ccsg.Node.performType.onExitTransitionDidStart);
- locRunningScene.performRecursive(_ccsg.Node.performType.onExit);
- }
-
- // issue #709. the root node (scene) should receive the cleanup message too
- // otherwise it might be leaked.
- if (this._sendCleanupToScene && locRunningScene)
- locRunningScene.performRecursive(_ccsg.Node.performType.cleanup);
- }
+ // var runningIsTransition = false, newIsTransition = false;
+ // if (cc.TransitionScene) {
+ // runningIsTransition = this._runningScene ? this._runningScene instanceof cc.TransitionScene : false;
+ // newIsTransition = this._nextScene ? this._nextScene instanceof cc.TransitionScene : false;
+ // }
+
+ // // If it is not a transition, call onExit/cleanup
+ // if (!newIsTransition) {
+ // var locRunningScene = this._runningScene;
+ // if (locRunningScene) {
+ // locRunningScene.performRecursive(_ccsg.Node.performType.onExitTransitionDidStart);
+ // locRunningScene.performRecursive(_ccsg.Node.performType.onExit);
+ // }
+
+ // // issue #709. the root node (scene) should receive the cleanup message too
+ // // otherwise it might be leaked.
+ // if (this._sendCleanupToScene && locRunningScene)
+ // locRunningScene.performRecursive(_ccsg.Node.performType.cleanup);
+ // }
this._runningScene = this._nextScene;
cc.renderer.childrenOrderDirty = true;
this._nextScene = null;
- if ((!runningIsTransition) && (this._runningScene !== null)) {
- this._runningScene.performRecursive(_ccsg.Node.performType.onEnter);
- this._runningScene.performRecursive(_ccsg.Node.performType.onEnterTransitionDidFinish);
- }
+ // if ((!runningIsTransition) && (this._runningScene !== null)) {
+ // this._runningScene.performRecursive(_ccsg.Node.performType.onEnter);
+ // this._runningScene.performRecursive(_ccsg.Node.performType.onEnterTransitionDidFinish);
+ // }
},
/**
@@ -1154,11 +1152,11 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
// pop stack until reaching desired level
while (c > level) {
var current = locScenesStack.pop();
- if (current.running) {
- current.performRecursive(_ccsg.Node.performType.onExitTransitionDidStart);
- current.performRecursive(_ccsg.Node.performType.onExit);
- }
- current.performRecursive(_ccsg.Node.performType.cleanup);
+ // if (current.running) {
+ // current.performRecursive(_ccsg.Node.performType.onExitTransitionDidStart);
+ // current.performRecursive(_ccsg.Node.performType.onExit);
+ // }
+ // current.performRecursive(_ccsg.Node.performType.cleanup);
c--;
}
this._nextScene = locScenesStack[locScenesStack.length - 1];
diff --git a/cocos2d/core/CCDirectorCanvas.js b/cocos2d/core/CCDirectorCanvas.js
deleted file mode 100644
index 773a612d3d9..00000000000
--- a/cocos2d/core/CCDirectorCanvas.js
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
- Copyright (c) 2008-2010 Ricardo Quesada
- 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.
- ****************************************************************************/
-
-require('./CCDirector');
-require('./CCGame');
-
-cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
-
- if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
- var _p = cc.Director.prototype;
-
- _p.getProjection = function (projection) {
- return this._projection;
- };
-
- _p.setProjection = function (projection) {
- this._projection = projection;
- this.emit(cc.Director.EVENT_PROJECTION_CHANGED, this);
- };
-
- _p.setDepthTest = function () {
- };
-
- _p.setClearColor = function (clearColor) {
- cc.renderer._clearColor = clearColor;
- cc.renderer._clearFillStyle = 'rgb(' + clearColor.r + ',' + clearColor.g + ',' + clearColor.b +')' ;
- };
-
- _p.setOpenGLView = function (openGLView) {
- // set size
- this._winSizeInPoints.width = cc._canvas.width; //this._openGLView.getDesignResolutionSize();
- this._winSizeInPoints.height = cc._canvas.height;
- this._openGLView = openGLView || cc.view;
- if (cc.eventManager)
- cc.eventManager.setEnabled(true);
- };
-
- _p.getVisibleSize = function () {
- //if (this._openGLView) {
- //return this._openGLView.getVisibleSize();
- //} else {
- return this.getWinSize();
- //}
- };
-
- _p.getVisibleOrigin = function () {
- //if (this._openGLView) {
- //return this._openGLView.getVisibleOrigin();
- //} else {
- return cc.p(0, 0);
- //}
- };
- }
-});
\ No newline at end of file
diff --git a/cocos2d/core/CCDirectorWebGL.js b/cocos2d/core/CCDirectorWebGL.js
deleted file mode 100644
index 0b9c9cc347f..00000000000
--- a/cocos2d/core/CCDirectorWebGL.js
+++ /dev/null
@@ -1,223 +0,0 @@
-/****************************************************************************
- Copyright (c) 2008-2010 Ricardo Quesada
- 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.
- ****************************************************************************/
-
-require('./CCDirector');
-require('./CCGame');
-require('../kazmath');
-
-var math = cc.math;
-
-cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
-
- // Do nothing under other render mode
- if (cc._renderType !== cc.game.RENDER_TYPE_WEBGL) {
- return;
- }
-
- /**
- * OpenGL projection protocol
- * @class
- * @extends cc._Class
- */
- cc.DirectorDelegate = cc._Class.extend(/** @lends cc.DirectorDelegate# */{
- /**
- * Called by CCDirector when the projection is updated, and "custom" projection is used
- */
- updateProjection: function () {
- }
- });
-
- var _p = cc.Director.prototype;
-
- var recursiveChild = function(node){
- if(node && node._renderCmd){
- node._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- var i, children = node._children;
- for(i=0; iccsg.Node is the root class of all node. Anything that gets drawn or contains things that get drawn is a ccsg.Node.
- * The most popular ccsg.Nodes are: ccsg.Scene, cc.Layer, _ccsg.Sprite, cc.Menu.
- *
- * Some ccsg.Node nodes provide extra functionality for them or their children.
- *
- * Properties configuration function
- * All properties in attrs will be set to the node,
- * when the setter of the node is available,
- * the property will be set via setter function.
- *
- * @function
- * @param {Object} attrs Properties to be set to node
- */
- attr: function (attrs) {
- for (var key in attrs) {
- this[key] = attrs[key];
- }
- },
-
- /**
- * Returns the skew degrees in X
- * The X skew angle of the node in degrees.
- * This angle describes the shear distortion in the X direction.
- * Thus, it is the angle between the Y axis and the left edge of the shape
- * The default skewX angle is 0. Positive values distort the node in a CW direction.
- *
- * @function
- * @return {Number} The X skew angle of the node in degrees.
- */
- getSkewX: function () {
- return this._skewX;
- },
-
- /**
- *
- * Changes the X skew angle of the node in degrees.
- *
- * This angle describes the shear distortion in the X direction.
- * Thus, it is the angle between the Y axis and the left edge of the shape
- * The default skewX angle is 0. Positive values distort the node in a CW direction.
- *
- * @function
- * @param {Number} newSkewX The X skew angle of the node in degrees.
- */
- setSkewX: function (newSkewX) {
- this._skewX = newSkewX;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- },
-
- /**
- * Returns the skew degrees in Y
- * The Y skew angle of the node in degrees.
- * This angle describes the shear distortion in the Y direction.
- * Thus, it is the angle between the X axis and the bottom edge of the shape
- * The default skewY angle is 0. Positive values distort the node in a CCW direction.
- *
- * @function
- * @return {Number} The Y skew angle of the node in degrees.
- */
- getSkewY: function () {
- return this._skewY;
- },
-
- /**
- *
- * Changes the Y skew angle of the node in degrees.
- *
- * This angle describes the shear distortion in the Y direction.
- * Thus, it is the angle between the X axis and the bottom edge of the shape
- * The default skewY angle is 0. Positive values distort the node in a CCW direction.
- *
- * @function
- * @param {Number} newSkewY The Y skew angle of the node in degrees.
- */
- setSkewY: function (newSkewY) {
- this._skewY = newSkewY;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- },
-
- /**
- * LocalZOrder is the 'key' used to sort the node relative to its siblings.
- *
- * The Node's parent will sort all its children based ont the LocalZOrder value.
- * If two nodes have the same LocalZOrder, then the node that was added first to the children's array
- * will be in front of the other node in the array.
- *
- * Also, the Scene Graph is traversed using the "In-Order" tree traversal algorithm ( http://en.wikipedia.org/wiki/Tree_traversal#In-order )
- *
- * And Nodes that have LocalZOder values smaller than 0 are the "left" subtree
- * While Nodes with LocalZOder greater than 0 are the "right" subtree.
- * @function
- * @param {Number} localZOrder
- */
- setLocalZOrder: function (localZOrder) {
- if (this._parent)
- this._parent.reorderChild(this, localZOrder);
- else
- this._localZOrder = localZOrder;
- cc.eventManager._setDirtyForNode(this);
- },
-
- //Helper function used by `setLocalZOrder`. Don't use it unless you know what you are doing.
- _setLocalZOrder: function (localZOrder) {
- this._localZOrder = localZOrder;
- },
-
- /**
- * Returns the local Z order of this node.
- * @function
- * @returns {Number} The local (relative to its siblings) Z order.
- */
- getLocalZOrder: function () {
- return this._localZOrder;
- },
-
- /**
- * Returns z order of this node
- * @function
- * @return {Number}
- * @deprecated since 3.0, please use getLocalZOrder instead
- */
- getZOrder: function () {
- cc.logID(1600);
- return this.getLocalZOrder();
- },
-
- /**
- *
- * Sets the Z order which stands for the drawing order, and reorder this node in its parent's children array.
- *
- * The Z order of node is relative to its "brothers": children of the same parent.
- * It's nothing to do with OpenGL's z vertex. This one only affects the draw order of nodes in cocos2d.
- * The larger number it is, the later this node will be drawn in each message loop.
- * Please refer to setVertexZ(float) for the difference.
- *
- * @function
- * @param {Number} z Z order of this node.
- * @deprecated since 3.0, please use setLocalZOrder instead
- */
- setZOrder: function (z) {
- cc.logID(1601);
- this.setLocalZOrder(z);
- },
-
- /**
- * Defines the oder in which the nodes are renderer.
- * Nodes that have a Global Z Order lower, are renderer first.
- *
- * In case two or more nodes have the same Global Z Order, the oder is not guaranteed.
- * The only exception if the Nodes have a Global Z Order == 0. In that case, the Scene Graph order is used.
- *
- * By default, all nodes have a Global Z Order = 0. That means that by default, the Scene Graph order is used to render the nodes.
- *
- * Global Z Order is useful when you need to render nodes in an order different than the Scene Graph order.
- *
- * Limitations: Global Z Order can't be used used by Nodes that have SpriteBatchNode as one of their ancestors.
- * And if ClippingNode is one of the ancestors, then "global Z order" will be relative to the ClippingNode.
- * @function
- * @param {Number} globalZOrder
- */
- setGlobalZOrder: function (globalZOrder) {
- if (this._globalZOrder !== globalZOrder) {
- this._globalZOrder = globalZOrder;
- cc.eventManager._setDirtyForNode(this);
- }
- },
-
- /**
- * Return the Node's Global Z Order.
- * @function
- * @returns {number} The node's global Z order
- */
- getGlobalZOrder: function () {
- return this._globalZOrder;
- },
-
- /**
- * Returns WebGL Z vertex of this node.
- * @function
- * @return {Number} WebGL Z vertex of this node
- */
- getVertexZ: function () {
- return this._vertexZ;
- },
-
- /**
- *
- * Sets the real WebGL Z vertex.
- *
- * Differences between openGL Z vertex and cocos2d Z order:
- * - WebGL Z modifies the Z vertex, and not the Z order in the relation between parent-children
- * - WebGL Z might require to set 2D projection
- * - cocos2d Z order works OK if all the nodes uses the same WebGL Z vertex. eg: vertexZ = 0
- *
- * @warning Use it at your own risk since it might break the cocos2d parent-children z order
- *
- * @function
- * @param {Number} Var
- */
- setVertexZ: function (Var) {
- this._customZ = this._vertexZ = Var;
- },
-
- /**
- * Returns the rotation (angle) of the node in degrees. 0 is the default rotation angle. Positive values rotate node clockwise.
- * @function
- * @return {Number} The rotation of the node in degrees.
- */
- getRotation: function () {
- if (this._rotationX !== this._rotationY)
- cc.logID(1602);
- return this._rotationX;
- },
-
- /**
- *
- * Sets the rotation (angle) of the node in degrees.
- *
- * 0 is the default rotation angle.
- * Positive values rotate node clockwise, and negative values for anti-clockwise.
- *
- * @function
- * @param {Number} newRotation The rotation of the node in degrees.
- */
- setRotation: function (newRotation) {
- this._rotationX = this._rotationY = newRotation;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- },
-
- /**
- * Returns the X axis rotation (angle) which represent a horizontal rotational skew of the node in degrees.
- * 0 is the default rotation angle. Positive values rotate node clockwise
- * (support only in WebGL rendering mode)
- * @function
- * @return {Number} The X rotation in degrees.
- */
- getRotationX: function () {
- return this._rotationX;
- },
-
- /**
- *
- * Sets the X rotation (angle) of the node in degrees which performs a horizontal rotational skew.
- * (support only in WebGL rendering mode)
- * 0 is the default rotation angle.
- * Positive values rotate node clockwise, and negative values for anti-clockwise.
- *
- * @param {Number} rotationX The X rotation in degrees which performs a horizontal rotational skew.
- */
- setRotationX: function (rotationX) {
- this._rotationX = rotationX;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- },
-
- /**
- * Returns the Y axis rotation (angle) which represent a vertical rotational skew of the node in degrees.
- * 0 is the default rotation angle. Positive values rotate node clockwise
- * (support only in WebGL rendering mode)
- * @function
- * @return {Number} The Y rotation in degrees.
- */
- getRotationY: function () {
- return this._rotationY;
- },
-
- /**
- *
- * Sets the Y rotation (angle) of the node in degrees which performs a vertical rotational skew.
- * (support only in WebGL rendering mode)
- * 0 is the default rotation angle.
- * Positive values rotate node clockwise, and negative values for anti-clockwise.
- *
- * @param rotationY The Y rotation in degrees.
- */
- setRotationY: function (rotationY) {
- this._rotationY = rotationY;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- },
-
- /**
- * Returns the scale factor of the node.
- * @warning: Assertion will fail when _scaleX != _scaleY.
- * @function
- * @return {Number} The scale factor
- */
- getScale: function () {
- if (this._scaleX !== this._scaleY)
- cc.logID(1603);
- return this._scaleX;
- },
-
- /**
- * Sets the scale factor of the node. 1.0 is the default scale factor. This function can modify the X and Y scale at the same time.
- * @function
- * @param {Number} scale or scaleX value
- * @param {Number} [scaleY=]
- */
- setScale: function (scale, scaleY) {
- this._scaleX = scale;
- this._scaleY = (scaleY || scaleY === 0) ? scaleY : scale;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- },
-
- /**
- * Returns the scale factor on X axis of this node
- * @function
- * @return {Number} The scale factor on X axis.
- */
- getScaleX: function () {
- return this._scaleX;
- },
-
- /**
- *
- * Changes the scale factor on X axis of this node
- * The default value is 1.0 if you haven't changed it before
- *
- * @function
- * @param {Number} newScaleX The scale factor on X axis.
- */
- setScaleX: function (newScaleX) {
- this._scaleX = newScaleX;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- },
-
- /**
- * Returns the scale factor on Y axis of this node
- * @function
- * @return {Number} The scale factor on Y axis.
- */
- getScaleY: function () {
- return this._scaleY;
- },
-
- /**
- *
- * Changes the scale factor on Y axis of this node
- * The Default value is 1.0 if you haven't changed it before.
- *
- * @function
- * @param {Number} newScaleY The scale factor on Y axis.
- */
- setScaleY: function (newScaleY) {
- this._scaleY = newScaleY;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- },
-
- /**
- *
- * Changes the position (x,y) of the node in cocos2d coordinates.
- * The original point (0,0) is at the left-bottom corner of screen.
- * Usually we use cc.p(x,y) to compose CCPoint object.
- * and Passing two numbers (x,y) is more efficient than passing CCPoint object.
- *
- * @function
- * @param {cc.Vec2|Number} newPosOrxValue The position (x,y) of the node in coordinates or the X coordinate for position
- * @param {Number} [yValue] Y coordinate for position
- * @example
- * var size = cc.winSize;
- * node.setPosition(size.width/2, size.height/2);
- */
- setPosition: function (newPosOrxValue, yValue) {
- var locPosition = this._position;
- if (yValue === undefined) {
- if(locPosition.x === newPosOrxValue.x && locPosition.y === newPosOrxValue.y)
- return;
- locPosition.x = newPosOrxValue.x;
- locPosition.y = newPosOrxValue.y;
- } else {
- if(locPosition.x === newPosOrxValue && locPosition.y === yValue)
- return;
- locPosition.x = newPosOrxValue;
- locPosition.y = yValue;
- }
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- },
-
- /**
- * Returns a copy of the position (x,y) of the node in cocos2d coordinates. (0,0) is the left-bottom corner.
- * @function
- * @return {cc.Vec2} The position (x,y) of the node in OpenGL coordinates
- */
- getPosition: function () {
- return cc.p(this._position);
- },
-
- /**
- * Returns the x axis position of the node in cocos2d coordinates.
- * @function
- * @return {Number}
- */
- getPositionX: function () {
- return this._position.x;
- },
-
- /**
- * Sets the x axis position of the node in cocos2d coordinates.
- * @function
- * @param {Number} x The new position in x axis
- */
- setPositionX: function (x) {
- this._position.x = x;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- },
-
- /**
- * Returns the y axis position of the node in cocos2d coordinates.
- * @function
- * @return {Number}
- */
- getPositionY: function () {
- return this._position.y;
- },
-
- /**
- * Sets the y axis position of the node in cocos2d coordinates.
- * @function
- * @param {Number} y The new position in y axis
- */
- setPositionY: function (y) {
- this._position.y = y;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- },
-
- /**
- * Returns the amount of children.
- * @function
- * @return {Number} The amount of children.
- */
- getChildrenCount: function () {
- return this._children.length;
- },
-
- /**
- * Returns an array of all children
- * Composing a "tree" structure is a very important feature of CCNode
- * @function
- * @return {Array} An array of children
- * @example
- * //This sample code traverses all children nodes, and set their position to (0,0)
- * var allChildren = parent.getChildren();
- * for(var i = 0; i< allChildren.length; i++) {
- * allChildren[i].setPosition(0,0);
- * }
- */
- getChildren: function () {
- return this._children;
- },
-
- /**
- * Returns if the node is visible
- * @function
- * @see _ccsg.Node#setVisible
- * @return {Boolean} true if the node is visible, false if the node is hidden.
- */
- isVisible: function () {
- return this._visible;
- },
-
- /**
- * Sets whether the node is visible
- * The default value is true
- * @function
- * @param {Boolean} visible Pass true to make the node visible, false to hide the node.
- */
- setVisible: function (visible) {
- if (this._visible !== visible) {
- this._visible = visible;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- cc.renderer.childrenOrderDirty = true;
- }
- },
-
- /**
- * Returns a copy of the anchor point.
- * Anchor point is the point around which all transformations and positioning manipulations take place.
- * It's like a pin in the node where it is "attached" to its parent.
- * The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
- * But you can use values higher than (1,1) and lower than (0,0) too.
- * The default anchor point is (0.5,0.5), so it starts at the center of the node.
- * @function
- * @return {cc.Vec2} The anchor point of node.
- */
- getAnchorPoint: function () {
- return cc.p(this._anchorPoint);
- },
-
- /**
- *
- * Sets the anchor point in percent.
- *
- * anchor point is the point around which all transformations and positioning manipulations take place.
- * It's like a pin in the node where it is "attached" to its parent.
- * The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.
- * But you can use values higher than (1,1) and lower than (0,0) too.
- * The default anchor point is (0.5,0.5), so it starts at the center of the node.
- *
- * @function
- * @param {cc.Vec2|Number} point The anchor point of node or The x axis anchor of node.
- * @param {Number} [y] The y axis anchor of node.
- */
- setAnchorPoint: function (point, y) {
- var locAnchorPoint = this._anchorPoint;
- if (y === undefined) {
- if ((point.x === locAnchorPoint.x) && (point.y === locAnchorPoint.y))
- return;
- locAnchorPoint.x = point.x;
- locAnchorPoint.y = point.y;
- } else {
- if ((point === locAnchorPoint.x) && (y === locAnchorPoint.y))
- return;
- locAnchorPoint.x = point;
- locAnchorPoint.y = y;
- }
- this._renderCmd._updateAnchorPointInPoint();
- },
-
- _getAnchorX: function () {
- return this._anchorPoint.x;
- },
- _setAnchorX: function (x) {
- if (this._anchorPoint.x === x) return;
- this._anchorPoint.x = x;
- this._renderCmd._updateAnchorPointInPoint();
- },
- _getAnchorY: function () {
- return this._anchorPoint.y;
- },
- _setAnchorY: function (y) {
- if (this._anchorPoint.y === y) return;
- this._anchorPoint.y = y;
- this._renderCmd._updateAnchorPointInPoint();
- },
-
- /**
- * Returns a copy of the anchor point in absolute pixels.
- * you can only read it. If you wish to modify it, use setAnchorPoint
- * @see _ccsg.Node#getAnchorPoint
- * @function
- * @return {cc.Vec2} The anchor point in absolute pixels.
- */
- getAnchorPointInPoints: function () {
- return this._renderCmd.getAnchorPointInPoints();
- },
-
- _getWidth: function () {
- return this._contentSize.width;
- },
- _setWidth: function (width) {
- this._contentSize.width = width;
- this._renderCmd._updateAnchorPointInPoint();
- },
- _getHeight: function () {
- return this._contentSize.height;
- },
- _setHeight: function (height) {
- this._contentSize.height = height;
- this._renderCmd._updateAnchorPointInPoint();
- },
-
- /**
- * Returns a copy the untransformed size of the node.
- * The contentSize remains the same no matter the node is scaled or rotated.
- * All nodes has a size. Layer and Scene has the same size of the screen by default.
- * @function
- * @return {Size} The untransformed size of the node.
- */
- getContentSize: function () {
- return cc.size(this._contentSize);
- },
-
- /**
- *
- * Sets the untransformed size of the node.
- *
- * The contentSize remains the same no matter the node is scaled or rotated.
- * All nodes has a size. Layer and Scene has the same size of the screen.
- *
- * @function
- * @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 locContentSize = this._contentSize;
- if (height === undefined) {
- if ((size.width === locContentSize.width) && (size.height === locContentSize.height))
- return;
- locContentSize.width = size.width;
- locContentSize.height = size.height;
- } else {
- if ((size === locContentSize.width) && (height === locContentSize.height))
- return;
- locContentSize.width = size;
- locContentSize.height = height;
- }
- this._renderCmd._updateAnchorPointInPoint();
- },
-
- /**
- *
- * Returns whether or not the node accepts event callbacks.
- * Running means the node accept event callbacks like onEnter(), onExit(), update()
- *
- * @function
- * @return {Boolean} Whether or not the node is running.
- */
- isRunning: function () {
- return this._running;
- },
-
- /**
- * Returns a reference to the parent node
- * @function
- * @return {_ccsg.Node} A reference to the parent node
- */
- getParent: function () {
- return this._parent;
- },
-
- /**
- * Sets the parent node
- * @param {_ccsg.Node} parent A reference to the parent node
- */
- setParent: function (parent) {
- this._parent = parent;
- var dirtyFlags = _ccsg.Node._dirtyFlags;
- this._renderCmd.setDirtyFlag(dirtyFlags.transformDirty | dirtyFlags.opacityDirty);
- },
-
- /**
- * Returns whether the anchor point will be ignored when you position this node.
- * When anchor point ignored, position will be calculated based on the origin point (0, 0) in parent's coordinates.
- * @function
- * @see _ccsg.Node#ignoreAnchorPointForPosition
- * @return {Boolean} true if the anchor point will be ignored when you position this node.
- */
- isIgnoreAnchorPointForPosition: function () {
- return this._ignoreAnchorPointForPosition;
- },
-
- /**
- *
- * Sets whether the anchor point will be ignored when you position this node.
- * When anchor point ignored, position will be calculated based on the origin point (0, 0) in parent's coordinates.
- * This is an internal method, only used by CCLayer and CCScene. Don't call it outside framework.
- * The default value is false, while in CCLayer and CCScene are true
- *
- * @function
- * @param {Boolean} newValue true if anchor point will be ignored when you position this node
- */
- setIgnoreAnchorPointForPosition: function (newValue) {
- if (newValue !== this._ignoreAnchorPointForPosition) {
- this._ignoreAnchorPointForPosition = newValue;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- }
- },
-
- /**
- * Returns a tag that is used to identify the node easily.
- * @function
- * @return {Number} An integer that identifies the node.
- * @example
- * //You can set tags to node then identify them easily.
- * // set tags
- * node1.setTag(TAG_PLAYER);
- * node2.setTag(TAG_MONSTER);
- * node3.setTag(TAG_BOSS);
- * parent.addChild(node1);
- * parent.addChild(node2);
- * parent.addChild(node3);
- * // identify by tags
- * var allChildren = parent.getChildren();
- * for(var i = 0; i < allChildren.length; i++){
- * switch(node.getTag()) {
- * case TAG_PLAYER:
- * break;
- * case TAG_MONSTER:
- * break;
- * case TAG_BOSS:
- * break;
- * }
- * }
- */
- getTag: function () {
- return this.tag;
- },
-
- /**
- * Changes the tag that is used to identify the node easily.
- * Please refer to getTag for the sample code.
- * @function
- * @see _ccsg.Node#getTag
- * @param {Number} tag A integer that identifies the node.
- */
- setTag: function (tag) {
- this.tag = tag;
- },
-
- /**
- * Changes the name that is used to identify the node easily.
- * @function
- * @param {String} name
- */
- setName: function(name){
- this._name = name;
- },
-
- /**
- * Returns a string that is used to identify the node.
- * @function
- * @returns {string} A string that identifies the node.
- */
- getName: function(){
- return this._name;
- },
-
- /**
- *
- * Update the arrival order.
- *
- * A node which called addChild subsequently will take a larger arrival order,
- * If two children have the same Z order, the child with larger arrival order will be drawn later.
- *
- * @function
- * @warning This method is used internally for zOrder sorting, don't call this method manually
- */
- updateOrderOfArrival: function () {
- this._arrivalOrder = ++cc.s_globalOrderOfArrival;
- },
-
- /**
- *
- * Returns the cc.Scheduler object used to schedule all "updates" and timers.
- *
- * @function
- * @return {cc.Scheduler} A CCScheduler object.
- */
- getScheduler: function () {
- return this._scheduler || cc.director.getScheduler();
- },
-
- /**
- *
- * Sets a CCScheduler object that is used to schedule all "updates" and timers.
- * IMPORTANT: If you set a new cc.Scheduler, then previously created timers/update are going to be removed.
- *
- * @function
- * @warning If you set a new CCScheduler, then previously created timers/update are going to be removed.
- * @param scheduler A cc.Scheduler object that is used to schedule all "update" and timers.
- */
- setScheduler: function (scheduler) {
- if (this._scheduler !== scheduler) {
- this.unscheduleAllCallbacks();
- this._scheduler = scheduler;
- }
- },
-
- /**
- * Returns a "local" axis aligned bounding box of the node.
- * @deprecated since v3.0, please use getBoundingBox instead
- * @return {Rect}
- */
- boundingBox: function(){
- cc.logID(1608);
- return this.getBoundingBox();
- },
-
- /**
- * Returns a "local" axis aligned bounding box of the node.
- * The returned box is relative only to its parent.
- * @function
- * @return {Rect} The calculated bounding box of the node
- */
- getBoundingBox: function () {
- var rect = cc.rect(0, 0, this._contentSize.width, this._contentSize.height);
- return cc._rectApplyAffineTransformIn(rect, this.getNodeToParentTransform());
- },
-
- /**
- * Stops all running actions and schedulers
- * @function
- */
- cleanup: function () {
- // actions
- this.stopAllActions();
- this.unscheduleAllCallbacks();
-
- // event
- cc.eventManager.removeListeners(this);
- },
-
- // composition: GET
- /**
- * Returns a child from the container given its tag
- * @function
- * @param {Number} aTag An identifier to find the child node.
- * @return {_ccsg.Node} a CCNode object whose tag equals to the input parameter
- */
- getChildByTag: function (aTag) {
- var __children = this._children;
- if (__children !== null) {
- for (var i = 0; i < __children.length; i++) {
- var node = __children[i];
- if (node && node.tag === aTag)
- return node;
- }
- }
- return null;
- },
-
- /**
- * Returns a child from the container given its name
- * @function
- * @param {String} name A name to find the child node.
- * @return {_ccsg.Node} a CCNode object whose name equals to the input parameter
- */
- getChildByName: function (name) {
- if (!name) {
- cc.log("Invalid name");
- return null;
- }
-
- var locChildren = this._children;
- for (var i = 0, len = locChildren.length; i < len; i++) {
- if (locChildren[i]._name === name)
- return locChildren[i];
- }
- return null;
- },
-
- // composition: ADD
-
- /** "add" logic MUST only be in this method
- *
- * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.
- * @function
- * @param {_ccsg.Node} child A child node
- * @param {Number} [localZOrder=] Z order for drawing priority. Please refer to setZOrder(int)
- * @param {Number|String} [tag=] An integer or a name to identify the node easily. Please refer to setTag(int) and setName(string)
- */
- addChild: function (child, localZOrder, tag) {
- localZOrder = localZOrder === undefined ? child._localZOrder : localZOrder;
- var name, setTag = false;
- if (tag === undefined) {
- name = child._name;
- } else if (typeof tag === 'string') {
- name = tag;
- tag = undefined;
- } else if (typeof tag === 'number') {
- setTag = true;
- name = "";
- }
-
- cc.assertID(child, 1606);
- cc.assertID(child._parent === null, 1605);
-
- this._addChildHelper(child, localZOrder, tag, name, setTag);
- },
-
- _addChildHelper: function(child, localZOrder, tag, name, setTag){
- if(!this._children)
- this._children = [];
-
- this._insertChild(child, localZOrder);
- if(setTag)
- child.setTag(tag);
- else
- child.setName(name);
-
- child.setParent(this);
- child.updateOrderOfArrival();
-
- if (this._running) {
- child.performRecursive(_ccsg.Node.performType.onEnter);
- // prevent onEnterTransitionDidFinish to be called twice when a node is added in onEnter
- if (this._isTransitionFinished)
- child.performRecursive(_ccsg.Node.performType.onEnterTransitionDidFinish);
- }
- child._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- if (this._cascadeColorEnabled)
- child._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.colorDirty);
- if (this._cascadeOpacityEnabled)
- child._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.opacityDirty);
- },
-
- // composition: REMOVE
- /**
- * Remove itself from its parent node. If cleanup is true, then also remove all actions and callbacks.
- * If the cleanup parameter is not passed, it will force a cleanup.
- * If the node orphan, then nothing happens.
- * @function
- * @param {Boolean} [cleanup=true] true if all actions and callbacks on this node should be removed, false otherwise.
- * @see _ccsg.Node#removeFromParentAndCleanup
- */
- removeFromParent: function (cleanup) {
- if (this._parent) {
- if (cleanup === undefined)
- cleanup = true;
- this._parent.removeChild(this, cleanup);
- }
- },
-
- /**
- * Removes this node itself from its parent node.
- * If the node orphan, then nothing happens.
- * @deprecated since v3.0, please use removeFromParent() instead
- * @param {Boolean} [cleanup=true] true if all actions and callbacks on this node should be removed, false otherwise.
- */
- removeFromParentAndCleanup: function (cleanup) {
- cc.logID(1607);
- this.removeFromParent(cleanup);
- },
-
- /** Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter.
- * If the cleanup parameter is not passed, it will force a cleanup.
- * "remove" logic MUST only be on this method
- * If a class wants to extend the 'removeChild' behavior it only needs
- * to override this method
- * @function
- * @param {_ccsg.Node} child The child node which will be removed.
- * @param {Boolean} [cleanup=true] true if all running actions and callbacks on the child node will be cleanup, false otherwise.
- */
- removeChild: function (child, cleanup) {
- // explicit nil handling
- if (this._children.length === 0)
- return;
-
- if (cleanup === undefined)
- cleanup = true;
- if (this._children.indexOf(child) > -1)
- this._detachChild(child, cleanup);
-
- //this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.visibleDirty);
- cc.renderer.childrenOrderDirty = true;
- },
-
- /**
- * Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter.
- * If the cleanup parameter is not passed, it will force a cleanup.
- * @function
- * @param {Number} tag An integer number that identifies a child node
- * @param {Boolean} [cleanup=true] true if all running actions and callbacks on the child node will be cleanup, false otherwise.
- * @see _ccsg.Node#removeChildByTag
- */
- removeChildByTag: function (tag, cleanup) {
- if (tag === cc.macro.NODE_TAG_INVALID)
- cc.logID(1609);
-
- var child = this.getChildByTag(tag);
- if (!child)
- cc.logID(1610, tag);
- else
- this.removeChild(child, cleanup);
- },
-
- /**
- * Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
- * @param {Boolean} [cleanup=true]
- */
- removeAllChildrenWithCleanup: function (cleanup) {
- this.removeAllChildren(cleanup);
- },
-
- /**
- * Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
- * If the cleanup parameter is not passed, it will force a cleanup.
- * @function
- * @param {Boolean} [cleanup=true] true if all running actions on all children nodes should be cleanup, false otherwise.
- */
- removeAllChildren: function (cleanup) {
- // not using detachChild improves speed here
- var __children = this._children;
- if (__children !== null) {
- if (cleanup === undefined)
- cleanup = true;
- for (var i = 0; i < __children.length; i++) {
- var node = __children[i];
- if (node) {
- if (this._running) {
- node.performRecursive(_ccsg.Node.performType.onExitTransitionDidStart);
- node.performRecursive(_ccsg.Node.performType.onExit);
- }
-
- // If you don't do cleanup, the node's actions will not get removed and the
- if (cleanup)
- node.performRecursive(_ccsg.Node.performType.cleanup);
-
- // set parent nil at the end
- node.parent = null;
- node._renderCmd.detachFromParent();
- }
- }
- this._children.length = 0;
- cc.renderer.childrenOrderDirty = true;
- }
- },
-
- _detachChild: function (child, doCleanup) {
- // IMPORTANT:
- // -1st do onExit
- // -2nd cleanup
- if (this._running) {
- child.performRecursive(_ccsg.Node.performType.onExitTransitionDidStart);
- child.performRecursive(_ccsg.Node.performType.onExit);
- }
-
- // If you don't do cleanup, the child's actions will not get removed and the
- if (doCleanup)
- child.performRecursive(_ccsg.Node.performType.cleanup);
-
- // set parent nil at the end
- child.parent = null;
- child._renderCmd.detachFromParent();
- cc.js.array.remove(this._children, child);
- },
-
- _insertChild: function (child, z) {
- cc.renderer.childrenOrderDirty = this._reorderChildDirty = true;
- this._children.push(child);
- child._setLocalZOrder(z);
- },
-
- setNodeDirty: function () {
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
- },
-
- /** Reorders a child according to a new z value.
- * The child MUST be already added.
- * @function
- * @param {_ccsg.Node} child An already added child node. It MUST be already added.
- * @param {Number} zOrder Z order for drawing priority. Please refer to setZOrder(int)
- */
- reorderChild: function (child, zOrder) {
- cc.assertID(child, 1617);
- if (this._children.indexOf(child) === -1) {
- cc.logID(1635);
- return;
- }
- if (zOrder === child.zIndex) {
- return;
- }
- cc.renderer.childrenOrderDirty = this._reorderChildDirty = true;
- child.updateOrderOfArrival();
- child._setLocalZOrder(zOrder);
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.orderDirty);
- },
-
- /**
- *
- * Sorts the children array once before drawing, instead of every time when a child is added or reordered.
- * This approach can improves the performance massively.
- *
- * @function
- * @note Don't call this manually unless a child added needs to be removed in the same frame
- */
- sortAllChildren: function () {
- if (this._reorderChildDirty) {
- var _children = this._children;
-
- // insertion sort
- var len = _children.length, i, j, tmp;
- for (i = 1; i < len; i++) {
- tmp = _children[i];
- j = i - 1;
-
- //continue moving element downwards while zOrder is smaller or when zOrder is the same but mutatedIndex is smaller
- while (j >= 0) {
- if (tmp._localZOrder < _children[j]._localZOrder) {
- _children[j + 1] = _children[j];
- } else if (tmp._localZOrder === _children[j]._localZOrder && tmp._arrivalOrder < _children[j]._arrivalOrder) {
- _children[j + 1] = _children[j];
- } else {
- break;
- }
- j--;
- }
- _children[j + 1] = tmp;
- }
-
- //don't need to check children recursively, that's done in visit of each child
- this._reorderChildDirty = false;
- }
- },
-
- /**
- * Render function using the canvas 2d context or WebGL context, internal usage only, please do not call this function
- * @function
- * @param {CanvasRenderingContext2D | WebGLRenderingContext} ctx The render context
- */
- draw: function (ctx) {
- // override me
- // Only use- this function to draw your staff.
- // DON'T draw your stuff outside this method
- },
-
- // Internal use only, do not call it by yourself,
- transformAncestors: function () {
- if (this._parent !== null) {
- this._parent.transformAncestors();
- this._parent.transform();
- }
- },
-
- //scene management
- /**
- *
- * Event callback that is invoked every time when CCNode enters the 'stage'.
- * If the CCNode enters the 'stage' with a transition, this event is called when the transition starts.
- * During onEnter you can't access a "sister/brother" node.
- * If you override onEnter, you must call its parent's onEnter function with this._super().
- *
- * @function
- */
- onEnter: function () {
- this._isTransitionFinished = false;
- this._running = true;//should be running before resumeSchedule
- this.resume();
- },
-
- performRecursive: function (callbackType) {
- var nodeCallbackType = _ccsg.Node.performType;
- if (callbackType >= nodeCallbackType.max) {
- return;
- }
-
- var index = 0;
- var children, child, curr, i, len;
- var stack = _ccsg.Node._performStacks[_ccsg.Node._performing];
- if (!stack) {
- stack = [];
- _ccsg.Node._performStacks.push(stack);
- }
- stack.length = 0;
- _ccsg.Node._performing++;
- curr = stack[0] = this;
- while (curr) {
- // Walk through children
- children = curr._children;
- if (children && children.length > 0) {
- for (i = 0, len = children.length; i < len; ++i) {
- child = children[i];
- stack.push(child);
- }
- }
-
- index++;
- curr = stack[index];
- }
- // Perform actual action
- switch (callbackType) {
- case nodeCallbackType.onEnter:
- for (i = stack.length - 1; i >= 0; --i) {
- curr = stack[i];
- stack[i] = null;
- if (!curr) continue;
- curr.onEnter();
- }
- break;
- case nodeCallbackType.onExit:
- for (i = stack.length - 1; i >= 0; --i) {
- curr = stack[i];
- stack[i] = null;
- if (!curr) continue;
- curr.onExit();
- }
- break;
- case nodeCallbackType.onEnterTransitionDidFinish:
- for (i = stack.length - 1; i >= 0; --i) {
- curr = stack[i];
- stack[i] = null;
- if (!curr) continue;
- curr.onEnterTransitionDidFinish();
- }
- break;
- case nodeCallbackType.cleanup:
- for (i = stack.length - 1; i >= 0; --i) {
- curr = stack[i];
- stack[i] = null;
- if (!curr) continue;
- curr.cleanup();
- }
- break;
- case nodeCallbackType.onExitTransitionDidStart:
- for (i = stack.length - 1; i >= 0; --i) {
- curr = stack[i];
- stack[i] = null;
- if (!curr) continue;
- curr.onExitTransitionDidStart();
- }
- break;
- }
-
- _ccsg.Node._performing--;
- },
-
- /**
- *
- * Event callback that is invoked when the CCNode enters in the 'stage'.
- * If the CCNode enters the 'stage' with a transition, this event is called when the transition finishes.
- * If you override onEnterTransitionDidFinish, you shall call its parent's onEnterTransitionDidFinish with this._super()
- *
- * @function
- */
- onEnterTransitionDidFinish: function () {
- this._isTransitionFinished = true;
- },
-
- /**
- * callback that is called every time the ccsg.Node leaves the 'stage'.
- * If the ccsg.Node leaves the 'stage' with a transition, this callback is called when the transition starts.
- * If you override onExitTransitionDidStart, you shall call its parent's onExitTransitionDidStart with this._super()
- * @function
- */
- onExitTransitionDidStart: function () {
- },
-
- /**
- *
- * callback that is called every time the ccsg.Node leaves the 'stage'.
- * If the ccsg.Node leaves the 'stage' with a transition, this callback is called when the transition finishes.
- * During onExit you can't access a sibling node.
- * If you override onExit, you shall call its parent's onExit with this._super().
- *
- * @function
- */
- onExit: function () {
- this._running = false;
- this.pause();
- },
-
- // actions
- /**
- * Executes an action, and returns the action that is executed.
- * The node becomes the action's target. Refer to cc.Action's getTarget()
- * @function
- * @warning Starting from v0.8 actions don't retain their target anymore.
- * @param {cc.Action} action
- * @return {cc.Action} An Action pointer
- */
- runAction: ActionManagerExist ? function (action) {
- cc.assertID(action, 1618);
-
- cc.director.getActionManager().addAction(action, this, !this._running);
- return action;
- } : emptyFunc,
-
- /**
- * Stops and removes all actions from the running action list .
- * @function
- */
- stopAllActions: ActionManagerExist ? function () {
- cc.director.getActionManager().removeAllActionsFromTarget(this);
- } : emptyFunc,
-
- /**
- * Stops and removes an action from the running action list.
- * @function
- * @param {cc.Action} action An action object to be removed.
- */
- stopAction: ActionManagerExist ? function (action) {
- cc.director.getActionManager().removeAction(action);
- } : emptyFunc,
-
- /**
- * Removes an action from the running action list by its tag.
- * @function
- * @param {Number} tag A tag that indicates the action to be removed.
- */
- stopActionByTag: ActionManagerExist ? function (tag) {
- if (tag === cc.Action.TAG_INVALID) {
- cc.logID(1612);
- return;
- }
- cc.director.getActionManager().removeActionByTag(tag, this);
- } : emptyFunc,
-
- /**
- * Returns an action from the running action list by its tag.
- * @function
- * @see _ccsg.Node#getTag and _ccsg.Node#setTag
- * @param {Number} tag
- * @return {cc.Action} The action object with the given tag.
- */
- getActionByTag: ActionManagerExist ? function (tag) {
- if (tag === cc.Action.TAG_INVALID) {
- cc.logID(1613);
- return null;
- }
- return cc.director.getActionManager().getActionByTag(tag, this);
- } : function () {
- return null;
- },
-
- /** Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays).
- * Composable actions are counted as 1 action. Example:
- * If you are running 1 Sequence of 7 actions, it will return 1.
- * If you are running 7 Sequences of 2 actions, it will return 7.
- * @function
- * @return {Number} The number of actions that are running plus the ones that are schedule to run
- */
- getNumberOfRunningActions: ActionManagerExist ? function () {
- return cc.director.getActionManager().getNumberOfRunningActionsInTarget(this);
- } : function () {
- return 0;
- },
-
- // _ccsg.Node - Callbacks
- // timers
- /**
- * schedules the "update" method.
- * It will use the order number 0. This method will be called every frame.
- * Scheduled methods with a lower order value will be called before the ones that have a higher order value.
- * Only one "update" method could be scheduled per node.
- * @function
- */
- scheduleUpdate: function () {
- this.scheduleUpdateWithPriority(0);
- },
-
- /**
- *
- * schedules the "update" callback function with a custom priority.
- * This callback function will be called every frame.
- * Scheduled callback functions with a lower priority will be called before the ones that have a higher value.
- * Only one "update" callback function could be scheduled per node (You can't have 2 'update' callback functions).
- *
- * @function
- * @param {Number} priority
- */
- scheduleUpdateWithPriority: function (priority) {
- this.scheduler.scheduleUpdate(this, priority, !this._running);
- },
-
- /**
- * Unschedules the "update" method.
- * @function
- * @see _ccsg.Node#scheduleUpdate
- */
- unscheduleUpdate: function () {
- this.scheduler.unscheduleUpdate(this);
- },
-
- /**
- * Schedules a custom selector.
- * If the selector is already scheduled, then the interval parameter will be updated without scheduling it again.
- * @function
- * @param {function} callback A function wrapped as a selector
- * @param {Number} interval Tick interval in seconds. 0 means tick every frame. If interval = 0, it's recommended to use scheduleUpdate() instead.
- * @param {Number} repeat The selector will be executed (repeat + 1) times, you can use kCCRepeatForever for tick infinitely.
- * @param {Number} delay The amount of time that the first tick will wait before execution.
- * @param {String} key The only string identifying the callback
- */
- schedule: function (callback, interval, repeat, delay, key) {
- var len = arguments.length;
- if (typeof callback === "function") {
- //callback, interval, repeat, delay, key
- if (len === 1) {
- //callback
- interval = 0;
- repeat = cc.macro.REPEAT_FOREVER;
- delay = 0;
- key = this.__instanceId;
- } else if (len === 2) {
- if (typeof interval === "number") {
- //callback, interval
- repeat = cc.macro.REPEAT_FOREVER;
- delay = 0;
- key = this.__instanceId;
- } else {
- //callback, key
- key = interval;
- interval = 0;
- repeat = cc.macro.REPEAT_FOREVER;
- delay = 0;
- }
- } else if (len === 3) {
- if (typeof repeat === "string") {
- //callback, interval, key
- key = repeat;
- repeat = cc.macro.REPEAT_FOREVER;
- } else {
- //callback, interval, repeat
- key = this.__instanceId;
- }
- delay = 0;
- } else if (len === 4) {
- key = this.__instanceId;
- }
- } else {
- //selector
- //selector, interval
- //selector, interval, repeat, delay
- if (len === 1) {
- interval = 0;
- repeat = cc.macro.REPEAT_FOREVER;
- delay = 0;
- } else if (len === 2) {
- repeat = cc.macro.REPEAT_FOREVER;
- delay = 0;
- }
- }
-
- cc.assertID(callback, 1619);
- cc.assertID(interval >= 0, 1620);
-
- interval = interval || 0;
- repeat = isNaN(repeat) ? cc.macro.REPEAT_FOREVER : repeat;
- delay = delay || 0;
-
- this.scheduler.schedule(callback, this, interval, repeat, delay, !this._running, key);
- },
-
- /**
- * Schedules a callback function that runs only once, with a delay of 0 or larger
- * @function
- * @see _ccsg.Node#schedule
- * @param {function} callback A function wrapped as a selector
- * @param {Number} delay The amount of time that the first tick will wait before execution.
- * @param {String} key The only string identifying the callback
- */
- scheduleOnce: function (callback, delay, key) {
- //selector, delay
- //callback, delay, key
- if (key === undefined)
- key = this.__instanceId;
- this.schedule(callback, 0, 0, delay, key);
- },
-
- /**
- * unschedules a custom callback function.
- * @function
- * @see _ccsg.Node#schedule
- * @param {function} callback_fn A function wrapped as a selector
- */
- unschedule: function (callback_fn) {
- //key
- //selector
- if (!callback_fn)
- return;
-
- this.scheduler.unschedule(callback_fn, this);
- },
-
- /**
- * unschedule all scheduled callback functions: custom callback functions, and the 'update' callback function.
- * Actions are not affected by this method.
- * @function
- */
- unscheduleAllCallbacks: function () {
- this.scheduler.unscheduleAllForTarget(this);
- },
-
- /**
- * Resumes all scheduled selectors and actions.
- * This method is called internally by onEnter
- * @function
- * @deprecated since v3.0, please use resume() instead
- */
- resumeSchedulerAndActions: function () {
- cc.logID(1614);
- this.resume();
- },
-
- /**
- * Resumes all scheduled selectors and actions.
- * This method is called internally by onEnter
- */
- resume: function () {
- this.scheduler.resumeTarget(this);
- ActionManagerExist && cc.director.getActionManager().resumeTarget(this);
- cc.eventManager.resumeTarget(this);
- },
-
- /**
- * Pauses all scheduled selectors and actions.
- * This method is called internally by onExit
- * @deprecated since v3.0, please use pause instead
- * @function
- */
- pauseSchedulerAndActions: function () {
- cc.logID(1615);
- this.pause();
- },
-
- /**
- * Pauses all scheduled selectors and actions.
- * This method is called internally by onExit
- * @function
- */
- pause: function () {
- this.scheduler.pauseTarget(this);
- ActionManagerExist && cc.director.getActionManager().pauseTarget(this);
- cc.eventManager.pauseTarget(this);
- },
-
- /**
- * Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates.
- * The matrix is in Pixels.
- * @function
- * @return {cc.AffineTransform}
- */
- getParentToNodeTransform: function () {
- return this._renderCmd.getParentToNodeTransform();
- },
-
- /**
- * @function
- * @deprecated since v3.0, please use getParentToNodeTransform instead
- */
- parentToNodeTransform: function () {
- return this.getParentToNodeTransform();
- },
-
- /**
- * Returns the world affine transform matrix. The matrix is in Pixels.
- * @function
- * @return {cc.AffineTransform}
- */
- getNodeToWorldTransform: function () {
- var t = this.getNodeToParentTransform();
- for (var p = this._parent; p !== null; p = p.parent)
- t = cc.affineTransformConcat(t, p.getNodeToParentTransform());
- return t;
- },
-
- /**
- * @function
- * @deprecated since v3.0, please use getNodeToWorldTransform instead
- */
- nodeToWorldTransform: function () {
- return this.getNodeToWorldTransform();
- },
-
- /**
- * Returns the inverse world affine transform matrix. The matrix is in Pixels.
- * @function
- * @return {cc.AffineTransform}
- */
- getWorldToNodeTransform: function () {
- return cc.affineTransformInvert(this.getNodeToWorldTransform());
- },
-
- /**
- * @function
- * @deprecated since v3.0, please use getWorldToNodeTransform instead
- */
- worldToNodeTransform: function () {
- return this.getWorldToNodeTransform();
- },
-
- /**
- * Converts a Point to node (local) space coordinates. The result is in Points.
- * @function
- * @param {cc.Vec2} worldPoint
- * @return {cc.Vec2}
- */
- convertToNodeSpace: function (worldPoint) {
- return cc.pointApplyAffineTransform(worldPoint, this.getWorldToNodeTransform());
- },
-
- /**
- * Converts a Point to world space coordinates. The result is in Points.
- * @function
- * @param {cc.Vec2} nodePoint
- * @return {cc.Vec2}
- */
- convertToWorldSpace: function (nodePoint) {
- nodePoint = nodePoint || cc.v2(0, 0);
- return cc.pointApplyAffineTransform(nodePoint, this.getNodeToWorldTransform());
- },
-
- /**
- * Converts a Point to node (local) space coordinates. The result is in Points.
- * treating the returned/received node point as anchor relative.
- * @function
- * @param {cc.Vec2} worldPoint
- * @return {cc.Vec2}
- */
- convertToNodeSpaceAR: function (worldPoint) {
- return cc.pSub(this.convertToNodeSpace(worldPoint), this._renderCmd.getAnchorPointInPoints());
- },
-
- /**
- * Converts a local Point to world space coordinates.The result is in Points.
- * treating the returned/received node point as anchor relative.
- * @function
- * @param {cc.Vec2} nodePoint
- * @return {cc.Vec2}
- */
- convertToWorldSpaceAR: function (nodePoint) {
- nodePoint = nodePoint || cc.v2(0, 0);
- var pt = cc.pAdd(nodePoint, this._renderCmd.getAnchorPointInPoints());
- return this.convertToWorldSpace(pt);
- },
-
- _convertToWindowSpace: function (nodePoint) {
- var worldPoint = this.convertToWorldSpace(nodePoint);
- return cc.director.convertToUI(worldPoint);
- },
-
- /** convenience methods which take a cc.Touch instead of cc.Vec2
- * @function
- * @param {cc.Touch} touch The touch object
- * @return {cc.Vec2}
- */
- convertTouchToNodeSpace: function (touch) {
- var point = touch.getLocation();
- return this.convertToNodeSpace(point);
- },
-
- /**
- * converts a cc.Touch (world coordinates) into a local coordinate. This method is AR (Anchor Relative).
- * @function
- * @param {cc.Touch} touch The touch object
- * @return {cc.Vec2}
- */
- convertTouchToNodeSpaceAR: function (touch) {
- var point = cc.director.convertToGL(touch.getLocation());
- return this.convertToNodeSpaceAR(point);
- },
-
- /**
- *
- * Calls children's updateTransform() method recursively.
- *
- * This method is moved from CCSprite, so it's no longer specific to CCSprite.
- * As the result, you apply CCSpriteBatchNode's optimization on your customed CCNode.
- * e.g., batchNode->addChild(myCustomNode), while you can only addChild(sprite) before.
- *
- * @function
- */
- updateTransform: function () {
- var children = this._children, node;
- for (var i = 0; i < children.length; i++) {
- var node = children[i];
- if (node)
- node.updateTransform();
- }
- },
-
- /**
- * Currently JavaScript Bindings (JSB), in some cases, needs to use retain and release. This is a bug in JSB,
- * and the ugly workaround is to use retain/release. So, these 2 methods were added to be compatible with JSB.
- * This is a hack, and should be removed once JSB fixes the retain/release bug
- * You will need to retain an object if you created an engine object and haven't added it into the scene graph during the same frame.
- * Otherwise, JSB's native autorelease pool will consider this object a useless one and release it directly,
- * when you want to use it later, a "Invalid Native Object" error will be raised.
- * The retain function can increase a reference count for the native object to avoid it being released,
- * you need to manually invoke release function when you think this object is no longer needed, otherwise, there will be memory learks.
- * retain and release function call should be paired in developer's game code.
- * @function
- * @see _ccsg.Node#release
- */
- retain: function () {
- },
- /**
- * Currently JavaScript Bindings (JSB), in some cases, needs to use retain and release. This is a bug in JSB,
- * and the ugly workaround is to use retain/release. So, these 2 methods were added to be compatible with JSB.
- * This is a hack, and should be removed once JSB fixes the retain/release bug
- * You will need to retain an object if you created an engine object and haven't added it into the scene graph during the same frame.
- * Otherwise, JSB's native autorelease pool will consider this object a useless one and release it directly,
- * when you want to use it later, a "Invalid Native Object" error will be raised.
- * The retain function can increase a reference count for the native object to avoid it being released,
- * you need to manually invoke release function when you think this object is no longer needed, otherwise, there will be memory learks.
- * retain and release function call should be paired in developer's game code.
- * @function
- * @see _ccsg.Node#retain
- */
- release: function () {
- },
-
- /**
- * Recursive method that visit its children and draw them
- * @function
- * @param {_ccsg.Node.RenderCmd} parentCmd
- */
- visit: function (parent) {
- var cmd = this._renderCmd, parentCmd = parent ? parent._renderCmd : null;
-
- // quick return if not visible
- if (!this._visible) {
- cmd._propagateFlagsDown(parentCmd);
- return;
- }
-
- var renderer = cc.renderer;
- cmd.visit(parentCmd);
-
- var i, children = this._children, len = children.length, child;
- if (len > 0) {
- if (this._reorderChildDirty) {
- this.sortAllChildren();
- }
- // draw children zOrder < 0
- for (i = 0; i < len; i++) {
- child = children[i];
- if (child._localZOrder < 0) {
- child.visit(this);
- }
- else {
- break;
- }
- }
-
- renderer.pushRenderCommand(cmd);
- for (; i < len; i++) {
- children[i].visit(this);
- }
- } else {
- renderer.pushRenderCommand(cmd);
- }
- cmd._dirtyFlag = 0;
- },
-
- /**
- * Performs view-matrix transformation based on position, scale, rotation and other attributes.
- * @function
- * @param {_ccsg.Node.RenderCmd} parentCmd parent's render command
- * @param {boolean} recursive whether call its children's transform
- */
- transform: function(parentCmd, recursive){
- this._renderCmd.transform(parentCmd, recursive);
- },
-
- /**
- * Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
- * The matrix is in Pixels.
- * @function
- * @return {cc.AffineTransform}
- * @deprecated since v3.0, please use getNodeToParentTransform instead
- */
- nodeToParentTransform: function(){
- return this.getNodeToParentTransform();
- },
-
- /**
- * Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
- * The matrix is in Pixels.
- * @function
- * @return {cc.AffineTransform} The affine transform object
- */
- getNodeToParentTransform: function(ancestor){
- var t = this._renderCmd.getNodeToParentTransform();
- if(ancestor){
- var T = {a: t.a, b: t.b, c: t.c, d: t.d, tx: t.tx, ty: t.ty};
- for(var p = this._parent; p != null && p != ancestor ; p = p.getParent()){
- cc.affineTransformConcatIn(T, p.getNodeToParentTransform());
- }
- return T;
- }else{
- return t;
- }
- },
-
- getNodeToParentAffineTransform: function(ancestor){
- return this.getNodeToParentTransform(ancestor);
- },
-
- /**
- * Return the shader program currently used for this node
- * @function
- * @return {cc.GLProgram} The shader program currently used for this node
- */
- getShaderProgram: function () {
- return this._renderCmd.getShaderProgram();
- },
-
- /**
- *
- * Sets the shader program for this node
- *
- * Since v2.0, each rendering node must set its shader program.
- * It should be set in initialize phase.
- *
- * @function
- * @param {cc.GLProgram} newShaderProgram The shader program which fetches from CCShaderCache.
- * @example
- * node.setGLProgram(cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_TEXTURECOLOR));
- */
- setShaderProgram: function (newShaderProgram) {
- this._renderCmd.setShaderProgram(newShaderProgram);
- },
-
- /**
- * Returns the state of OpenGL server side.
- * @function
- * @return {Number} The state of OpenGL server side.
- * @deprecated since v3.0, no need anymore
- */
- getGLServerState: function () {
- return 0;
- },
-
- /**
- * Sets the state of OpenGL server side.
- * @function
- * @param {Number} state The state of OpenGL server side.
- * @deprecated since v3.0, no need anymore
- */
- setGLServerState: function (state) {
- },
-
- /**
- * Returns a "world" axis aligned bounding box of the node.
- * @function
- * @return {Rect}
- */
- getBoundingBoxToWorld: function () {
- var rect = cc.rect(0, 0, this._contentSize.width, this._contentSize.height);
- var trans = this.getNodeToWorldTransform();
- cc._rectApplyAffineTransformIn(rect, trans);
-
- //query child's BoundingBox
- if (!this._children)
- return rect;
-
- var locChildren = this._children;
- for (var i = 0; i < locChildren.length; i++) {
- var child = locChildren[i];
- if (child && child._visible) {
- var childRect = child._getBoundingBoxToCurrentNode(trans);
- if (childRect)
- rect = cc.rectUnion(rect, childRect);
- }
- }
- return rect;
- },
-
- _getBoundingBoxToCurrentNode: function (parentTransform) {
- var rect = cc.rect(0, 0, this._contentSize.width, this._contentSize.height);
- var trans = (parentTransform === undefined) ? this.getNodeToParentTransform() : cc.affineTransformConcat(this.getNodeToParentTransform(), parentTransform);
- cc._rectApplyAffineTransformIn(rect, trans);
-
- //query child's BoundingBox
- if (!this._children)
- return rect;
-
- var locChildren = this._children;
- for (var i = 0; i < locChildren.length; i++) {
- var child = locChildren[i];
- if (child && child._visible) {
- var childRect = child._getBoundingBoxToCurrentNode(trans);
- if (childRect)
- rect = cc.rectUnion(rect, childRect);
- }
- }
- return rect;
- },
-
- /**
- * Returns the opacity of Node
- * @function
- * @returns {number} opacity
- */
- getOpacity: function () {
- return this._realOpacity;
- },
-
- /**
- * Returns the displayed opacity of Node,
- * the difference between displayed opacity and opacity is that displayed opacity is calculated based on opacity and parent node's opacity when cascade opacity enabled.
- * @function
- * @returns {number} displayed opacity
- */
- getDisplayedOpacity: function () {
- return this._renderCmd.getDisplayedOpacity();
- },
-
- /**
- * Sets the opacity of Node
- * @function
- * @param {Number} opacity
- */
- setOpacity: function (opacity) {
- this._realOpacity = opacity;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.opacityDirty);
- },
-
- /**
- * Update displayed opacity
- * @function
- * @param {Number} parentOpacity
- */
- updateDisplayedOpacity: function (parentOpacity) {
- //TODO this API shouldn't be public.
- this._renderCmd._updateDisplayOpacity(parentOpacity);
- },
-
- /**
- * Returns whether node's opacity value affect its child nodes.
- * @function
- * @returns {boolean}
- */
- isCascadeOpacityEnabled: function () {
- return this._cascadeOpacityEnabled;
- },
-
- /**
- * Enable or disable cascade opacity, if cascade enabled, child nodes' opacity will be the multiplication of parent opacity and its own opacity.
- * @function
- * @param {boolean} cascadeOpacityEnabled
- */
- setCascadeOpacityEnabled: function (cascadeOpacityEnabled) {
- if (this._cascadeOpacityEnabled === cascadeOpacityEnabled)
- return;
- this._cascadeOpacityEnabled = cascadeOpacityEnabled;
- this._renderCmd.setCascadeOpacityEnabledDirty();
- },
-
- /**
- * Returns the color of Node
- * @function
- * @returns {cc.Color}
- */
- getColor: function () {
- var locRealColor = this._realColor;
- return cc.color(locRealColor.r, locRealColor.g, locRealColor.b, locRealColor.a);
- },
-
- /**
- * Returns the displayed color of Node,
- * the difference between displayed color and color is that displayed color is calculated based on color and parent node's color when cascade color enabled.
- * @function
- * @returns {cc.Color}
- */
- getDisplayedColor: function () {
- return this._renderCmd.getDisplayedColor();
- },
-
- /**
- * Sets the color of Node.
- * When color doesn't include opacity value like cc.color(128,128,128), this function only change the color.
- * When color include opacity like cc.color(128,128,128,100), then this function will change the color and the opacity.
- * @function
- * @param {cc.Color} color The new color given
- */
- setColor: function (color) {
- var locRealColor = this._realColor;
- locRealColor.r = color.r;
- locRealColor.g = color.g;
- locRealColor.b = color.b;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.colorDirty);
- },
-
- /**
- * Update the displayed color of Node
- * @function
- * @param {cc.Color} parentColor
- */
- updateDisplayedColor: function (parentColor) {
- //TODO this API shouldn't be public.
- this._renderCmd._updateDisplayColor(parentColor);
- },
-
- /**
- * Returns whether node's color value affect its child nodes.
- * @function
- * @returns {boolean}
- */
- isCascadeColorEnabled: function () {
- return this._cascadeColorEnabled;
- },
-
- /**
- * Enable or disable cascade color, if cascade enabled, child nodes' opacity will be the cascade value of parent color and its own color.
- * @param {boolean} cascadeColorEnabled
- */
- setCascadeColorEnabled: function (cascadeColorEnabled) {
- if (this._cascadeColorEnabled === cascadeColorEnabled)
- return;
- this._cascadeColorEnabled = cascadeColorEnabled;
- this._renderCmd.setCascadeColorEnabledDirty();
- },
-
- /**
- * Set whether color should be changed with the opacity value,
- * useless in ccsg.Node, but this function is override in some class to have such behavior.
- * @function
- * @param {Boolean} opacityValue
- */
- setOpacityModifyRGB: function (opacityValue) {
- },
-
- /**
- * Get whether color should be changed with the opacity value
- * @function
- * @return {Boolean}
- */
- isOpacityModifyRGB: function () {
- return false;
- },
-
- _createRenderCmd: function () {
- if (cc._renderType === cc.game.RENDER_TYPE_CANVAS)
- return new _ccsg.Node.CanvasRenderCmd(this);
- else
- return new _ccsg.Node.WebGLRenderCmd(this);
- }
-});
-
-_ccsg.Node.extend = cc._Class.extend;
-
-// to support calling this._super in sub class
-_ccsg.Node.prototype.ctor = _ccsg.Node;
-
-_ccsg.Node.performType = {
- onEnter: 1,
- onExit: 2,
- cleanup: 3,
- onEnterTransitionDidFinish: 4,
- onExitTransitionDidStart: 5,
- max: 6
-};
-_ccsg.Node._performStacks = [[]];
-_ccsg.Node._performing = 0;
-
-
-var SameNameGetSets = ['skewX', 'skewY', 'vertexZ', 'rotation', 'rotationX', 'rotationY', 'scale', 'scaleX', 'scaleY',
- 'children', 'childrenCount', 'parent', 'scheduler', 'shaderProgram', 'opacity', 'color'];
-var DiffNameGetSets = {
- x: ['getPositionX', 'setPositionX'],
- y: ['getPositionY', 'setPositionY'],
- width: ['_getWidth', '_setWidth'],
- height: ['_getHeight', '_setHeight'],
- anchorX: ['_getAnchorX', '_setAnchorX'],
- anchorY: ['_getAnchorY', '_setAnchorY'],
- zIndex: ['getLocalZOrder', 'setLocalZOrder'],
- visible: ['isVisible', 'setVisible'],
- running: ['isRunning'],
- ignoreAnchor: ['isIgnoreAnchorPointForPosition', 'setIgnoreAnchorPointForPosition'],
- opacityModifyRGB: ['isOpacityModifyRGB', 'setOpacityModifyRGB'],
- cascadeOpacity: ['isCascadeOpacityEnabled', 'setCascadeOpacityEnabled'],
- cascadeColor: ['isCascadeColorEnabled', 'setCascadeColorEnabled'],
-};
-Misc.propertyDefine(_ccsg.Node, SameNameGetSets, DiffNameGetSets);
diff --git a/cocos2d/core/base-nodes/CCSGNodeBaseRenderCmd.js b/cocos2d/core/base-nodes/CCSGNodeBaseRenderCmd.js
deleted file mode 100644
index acba7e79c2e..00000000000
--- a/cocos2d/core/base-nodes/CCSGNodeBaseRenderCmd.js
+++ /dev/null
@@ -1,572 +0,0 @@
-/****************************************************************************
- 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.
- ****************************************************************************/
-
-
-//---------------------- Customer render cmd --------------------
-cc.CustomRenderCmd = function (target, func) {
- this._needDraw = true;
- this._target = target;
- this._callback = func;
-};
-cc.CustomRenderCmd.prototype.rendering = function (ctx, scaleX, scaleY) {
- if (!this._callback)
- return;
- this._callback.call(this._target, ctx, scaleX, scaleY);
-};
-
-var dirtyFlags = _ccsg.Node._dirtyFlags = {
- transformDirty: 1 << 0,
- visibleDirty: 1 << 1,
- colorDirty: 1 << 2,
- opacityDirty: 1 << 3,
- cacheDirty: 1 << 4,
- orderDirty: 1 << 5,
- textDirty: 1 << 6,
- gradientDirty: 1 << 7,
- textureDirty: 1 << 8,
- contentDirty: 1 << 9,
- cullingDirty: 1 << 10,
- COUNT: 9
-};
-cc.js.get(dirtyFlags, 'all', function () {
- var count = dirtyFlags.COUNT;
- return (1 << count) - 1;
-}, false);
-_ccsg.Node._requestDirtyFlag = function (key) {
- cc.assertID(!dirtyFlags[key], 1622, key);
-
- var count = dirtyFlags.COUNT;
- var value = 1 << count;
- dirtyFlags[key] = value;
- dirtyFlags.COUNT++;
- return value;
-};
-
-var ONE_DEGREE = Math.PI / 180;
-
-function walkChildTree (root, funcName) {
- var index = 1;
- var children, child, curr, parentCmd, i, len;
- var stack = _ccsg.Node._performStacks[_ccsg.Node._performing];
- if (!stack) {
- stack = [];
- _ccsg.Node._performStacks.push(stack);
- }
- stack.length = 0;
- _ccsg.Node._performing++;
- stack[0] = root;
-
- var childChildren;
- while (index) {
- index--;
- curr = stack[index];
- // Avoid memory leak
- stack[index] = null;
- if (!curr) continue;
- children = curr._children;
- if (children && children.length > 0) {
- parentCmd = curr._renderCmd;
- for (i = 0, len = children.length; i < len; ++i) {
- child = children[i];
- stack[index] = child;
- index++;
- child._renderCmd[funcName](parentCmd);
- }
- }
- }
- _ccsg.Node._performing--;
-}
-
-//-------------------------Base -------------------------
-_ccsg.Node.RenderCmd = function (renderable) {
- this._node = renderable;
- this._anchorPointInPoints = new cc.Vec2(0, 0);
-
- this._needDraw = false;
- this._dirtyFlag = 1;
- this._curLevel = -1;
-
- this._cameraFlag = 0;
-
- this._displayedColor = new cc.Color(255, 255, 255, 255);
- this._displayedOpacity = 255;
- this._cascadeColorEnabledDirty = false;
- this._cascadeOpacityEnabledDirty = false;
-
- this._transform = {a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0};
- this._worldTransform = {a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0};
- this._inverse = {a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0};
- this._transformUpdated = false;
-
- cc.renderer.pushDirtyNode(this);
-};
-
-_ccsg.Node.RenderCmd.prototype = {
- constructor: _ccsg.Node.RenderCmd,
-
- _ctor: _ccsg.Node.RenderCmd,
-
- getAnchorPointInPoints: function(){
- return cc.p(this._anchorPointInPoints);
- },
-
- getDisplayedColor: function(){
- var tmpColor = this._displayedColor;
- return cc.color(tmpColor.r, tmpColor.g, tmpColor.b, tmpColor.a);
- },
-
- getDisplayedOpacity: function(){
- return this._displayedOpacity;
- },
-
- setCascadeColorEnabledDirty: function(){
- this._cascadeColorEnabledDirty = true;
- this.setDirtyFlag(dirtyFlags.colorDirty);
- },
-
- setCascadeOpacityEnabledDirty:function(){
- this._cascadeOpacityEnabledDirty = true;
- this.setDirtyFlag(dirtyFlags.opacityDirty);
- },
-
- getParentToNodeTransform: function(){
- if (this._dirtyFlag & dirtyFlags.transformDirty) {
- cc.affineTransformInvertOut(this.getNodeToParentTransform(), this._inverse);
- }
- return this._inverse;
- },
-
- detachFromParent: function(){},
-
- _updateAnchorPointInPoint: function() {
- var locAPP = this._anchorPointInPoints, locSize = this._node._contentSize, locAnchorPoint = this._node._anchorPoint;
- locAPP.x = locSize.width * locAnchorPoint.x;
- locAPP.y = locSize.height * locAnchorPoint.y;
- this.setDirtyFlag(dirtyFlags.transformDirty);
- },
-
- setDirtyFlag: function(dirtyFlag){
- if (this._dirtyFlag === 0 && dirtyFlag !== 0)
- cc.renderer.pushDirtyNode(this);
- this._dirtyFlag |= dirtyFlag;
- },
-
- getParentRenderCmd: function(){
- if(this._node && this._node._parent && this._node._parent._renderCmd)
- return this._node._parent._renderCmd;
- return null;
- },
-
- updateTransform: function (parentCmd, recursive) {
- var node = this._node,
- pt = parentCmd ? parentCmd._worldTransform : null,
- t = this._transform,
- wt = this._worldTransform; //get the world transform
-
- if (!this._transformUpdated) {
- var hasRotation = node._rotationX || node._rotationY;
- var hasSkew = node._skewX || node._skewY;
- var sx = node._scaleX, sy = node._scaleY;
- var appX = this._anchorPointInPoints.x, appY = this._anchorPointInPoints.y;
- var a = 1, b = 0, c = 0, d = 1;
- if (hasRotation || hasSkew) {
- // position
- t.tx = node._position.x;
- t.ty = node._position.y;
-
- // rotation
- if (hasRotation) {
- var rotationRadiansX = node._rotationX * ONE_DEGREE;
- c = Math.sin(rotationRadiansX);
- d = Math.cos(rotationRadiansX);
- if (node._rotationY === node._rotationX) {
- a = d;
- b = -c;
- }
- else {
- var rotationRadiansY = node._rotationY * ONE_DEGREE;
- a = Math.cos(rotationRadiansY);
- b = -Math.sin(rotationRadiansY);
- }
- }
-
- // scale
- t.a = a *= sx;
- t.b = b *= sx;
- t.c = c *= sy;
- t.d = d *= sy;
-
- // skew
- if (hasSkew) {
- var skx = Math.tan(node._skewX * ONE_DEGREE);
- var sky = Math.tan(node._skewY * ONE_DEGREE);
- if (skx === Infinity)
- skx = 99999999;
- if (sky === Infinity)
- sky = 99999999;
- t.a = a + c * sky;
- t.b = b + d * sky;
- t.c = c + a * skx;
- t.d = d + b * skx;
- }
-
- if (appX || appY) {
- t.tx -= t.a * appX + t.c * appY;
- t.ty -= t.b * appX + t.d * appY;
- // adjust anchorPoint
- if (node._ignoreAnchorPointForPosition) {
- t.tx += appX;
- t.ty += appY;
- }
- }
- }
- else {
- t.a = sx;
- t.b = 0;
- t.c = 0;
- t.d = sy;
- t.tx = node._position.x;
- t.ty = node._position.y;
-
- if (appX || appY) {
- t.tx -= t.a * appX;
- t.ty -= t.d * appY;
- // adjust anchorPoint
- if (node._ignoreAnchorPointForPosition) {
- t.tx += appX;
- t.ty += appY;
- }
- }
- }
- }
-
- // update world transform
- if (pt) {
- wt.a = t.a * pt.a + t.b * pt.c;
- wt.b = t.a * pt.b + t.b * pt.d;
- wt.c = t.c * pt.a + t.d * pt.c;
- wt.d = t.c * pt.b + t.d * pt.d;
- wt.tx = t.tx * pt.a + t.ty * pt.c + pt.tx;
- wt.ty = t.tx * pt.b + t.ty * pt.d + pt.ty;
- } else {
- wt.a = t.a;
- wt.b = t.b;
- wt.c = t.c;
- wt.d = t.d;
- wt.tx = t.tx;
- wt.ty = t.ty;
- }
- },
-
- transform: function (parentCmd, recursive) {
- this.updateTransform(parentCmd);
-
- if (this._currentRegion) {
- this._updateCurrentRegions();
- this._notifyRegionStatus && this._notifyRegionStatus(_ccsg.Node.CanvasRenderCmd.RegionStatus.DirtyDouble);
- }
-
- if (cc.macro.ENABLE_CULLING) {
- this._updateCameraFlag(parentCmd);
-
- if (this._doCulling) {
- this._doCulling();
- }
- }
- else if (this._doCulling) {
- this._needDraw = true;
- }
-
- if (recursive) {
- walkChildTree(this._node, 'transform');
- }
- },
-
- _updateCameraFlag: function (parentCmd) {
- var Camera = cc.Camera;
-
- if (cc._renderType === cc.game.RENDER_TYPE_WEBGL && Camera) {
- if (parentCmd && this._cameraFlag != Camera.flags.InCamera) {
- this._cameraFlag = parentCmd._cameraFlag > 0 ? Camera.flags.ParentInCamera : 0;
- }
- }
-
- },
-
- culling: function (parentCmd, recursive) {
- if (!cc.macro.ENABLE_CULLING) {
- if (this._doCulling) {
- this._needDraw = true;
- }
- return;
- }
-
- this._updateCameraFlag(parentCmd);
-
- if (this._doCulling) {
- this._doCulling();
- }
-
- if (recursive) {
- walkChildTree(this._node, 'culling');
- }
- },
-
- getNodeToParentTransform: function () {
- if (this._dirtyFlag & dirtyFlags.transformDirty) {
- this.transform();
- }
- return this._transform;
- },
-
- setNodeToParentTransform: function(transform) {
- if (transform) {
- // use specified transform
- this._transform = transform;
- this._transformUpdated = true;
- } else {
- // not use the specified transform
- this._transformUpdated = false;
- }
- this.setDirtyFlag(dirtyFlags.transformDirty);
- },
-
- _propagateFlagsDown: function(parentCmd) {
- if (!parentCmd) return;
-
- //return;
- var locFlag = this._dirtyFlag;
- var parentNode = parentCmd._node;
- var parentFlag = parentCmd._dirtyFlag;
-
- // There is a possibility:
- // The parent element changed color, child element not change
- // This will cause the parent element changed color
- // But while the child element does not enter the circulation
- // Here will be reset state in last
- // In order the child elements get the parent state
- if(parentNode._cascadeColorEnabled && (parentFlag & dirtyFlags.colorDirty))
- locFlag |= dirtyFlags.colorDirty;
-
- if(parentNode._cascadeOpacityEnabled && (parentFlag & dirtyFlags.opacityDirty))
- locFlag |= dirtyFlags.opacityDirty;
-
- if (parentFlag & dirtyFlags.transformDirty) {
- locFlag |= dirtyFlags.transformDirty;
- }
-
- if (parentFlag & dirtyFlags.cullingDirty) {
- locFlag |= dirtyFlags.cullingDirty;
- }
-
- this._dirtyFlag = locFlag;
- },
-
- visit: function (parentCmd) {
- var node = this._node, renderer = cc.renderer;
-
- if (parentCmd) {
- this._curLevel = parentCmd._curLevel + 1;
- }
- this._propagateFlagsDown(parentCmd);
-
- if (isNaN(node._customZ)) {
- node._vertexZ = renderer.assignedZ;
- renderer.assignedZ += renderer.assignedZStep;
- }
-
- this._syncStatus(parentCmd);
- },
-
- _updateDisplayColor: function (parentColor) {
- var node = this._node;
- var locDispColor = this._displayedColor, locRealColor = node._realColor;
- var i, len, selChildren, item;
- this._notifyRegionStatus && this._notifyRegionStatus(_ccsg.Node.CanvasRenderCmd.RegionStatus.Dirty);
- if (this._cascadeColorEnabledDirty && !node._cascadeColorEnabled) {
- locDispColor.r = locRealColor.r;
- locDispColor.g = locRealColor.g;
- locDispColor.b = locRealColor.b;
- var whiteColor = new cc.Color(255, 255, 255, 255);
- selChildren = node._children;
- for (i = 0, len = selChildren.length; i < len; i++) {
- item = selChildren[i];
- if (item && item._renderCmd)
- item._renderCmd._updateDisplayColor(whiteColor);
- }
- this._cascadeColorEnabledDirty = false;
- } else {
- if (parentColor === undefined) {
- var locParent = node._parent;
- if (locParent && locParent._cascadeColorEnabled)
- parentColor = locParent.getDisplayedColor();
- else
- parentColor = cc.Color.WHITE;
- }
- locDispColor.r = 0 | (locRealColor.r * parentColor.r / 255.0);
- locDispColor.g = 0 | (locRealColor.g * parentColor.g / 255.0);
- locDispColor.b = 0 | (locRealColor.b * parentColor.b / 255.0);
- if (node._cascadeColorEnabled) {
- selChildren = node._children;
- for (i = 0, len = selChildren.length; i < len; i++) {
- item = selChildren[i];
- if (item && item._renderCmd){
- item._renderCmd._updateDisplayColor(locDispColor);
- item._renderCmd._updateColor();
- }
- }
- }
- }
- this._dirtyFlag &= ~dirtyFlags.colorDirty;
- },
-
- _updateDisplayOpacity: function (parentOpacity) {
- var node = this._node;
- var i, len, selChildren, item;
- this._notifyRegionStatus && this._notifyRegionStatus(_ccsg.Node.CanvasRenderCmd.RegionStatus.Dirty);
- if (this._cascadeOpacityEnabledDirty && !node._cascadeOpacityEnabled) {
- this._displayedOpacity = node._realOpacity;
- selChildren = node._children;
- for (i = 0, len = selChildren.length; i < len; i++) {
- item = selChildren[i];
- if (item && item._renderCmd)
- item._renderCmd._updateDisplayOpacity(255);
- }
- this._cascadeOpacityEnabledDirty = false;
- } else {
- if (parentOpacity === undefined) {
- var locParent = node._parent;
- parentOpacity = 255;
- if (locParent && locParent._cascadeOpacityEnabled)
- parentOpacity = locParent.getDisplayedOpacity();
- }
- this._displayedOpacity = node._realOpacity * parentOpacity / 255.0;
- if (node._cascadeOpacityEnabled) {
- selChildren = node._children;
- for (i = 0, len = selChildren.length; i < len; i++) {
- item = selChildren[i];
- if (item && item._renderCmd){
- item._renderCmd._updateDisplayOpacity(this._displayedOpacity);
- item._renderCmd._updateColor();
- }
- }
- }
- }
- this._dirtyFlag &= ~dirtyFlags.opacityDirty;
- },
-
- _syncDisplayColor : function (parentColor) {
- var node = this._node, locDispColor = this._displayedColor, locRealColor = node._realColor;
- if (parentColor === undefined) {
- var locParent = node._parent;
- if (locParent && locParent._cascadeColorEnabled)
- parentColor = locParent.getDisplayedColor();
- else
- parentColor = cc.Color.WHITE;
- }
- locDispColor.r = 0 | (locRealColor.r * parentColor.r / 255.0);
- locDispColor.g = 0 | (locRealColor.g * parentColor.g / 255.0);
- locDispColor.b = 0 | (locRealColor.b * parentColor.b / 255.0);
- },
-
- _syncDisplayOpacity : function (parentOpacity) {
- var node = this._node;
- if (parentOpacity === undefined) {
- var locParent = node._parent;
- parentOpacity = 255;
- if (locParent && locParent._cascadeOpacityEnabled)
- parentOpacity = locParent.getDisplayedOpacity();
- }
- this._displayedOpacity = node._realOpacity * parentOpacity / 255.0;
- },
-
- _updateColor: function(){},
-
- updateStatus: function () {
- var locFlag = this._dirtyFlag;
- var colorDirty = locFlag & dirtyFlags.colorDirty,
- opacityDirty = locFlag & dirtyFlags.opacityDirty;
-
- if (locFlag & dirtyFlags.contentDirty) {
- this._notifyRegionStatus && this._notifyRegionStatus(_ccsg.Node.CanvasRenderCmd.RegionStatus.Dirty);
- this._dirtyFlag &= ~dirtyFlags.contentDirty;
- }
-
- if (colorDirty)
- this._updateDisplayColor();
-
- if (opacityDirty)
- this._updateDisplayOpacity();
-
- if (colorDirty || opacityDirty)
- this._updateColor();
-
- if (locFlag & dirtyFlags.transformDirty) {
- var parentCmd = this.getParentRenderCmd();
-
- //update the transform
- this.transform(parentCmd, true);
- this._dirtyFlag &= ~dirtyFlags.transformDirty;
- this._dirtyFlag &= ~dirtyFlags.cullingDirty;
- }
- else if (locFlag & dirtyFlags.cullingDirty) {
- this.culling(parentCmd, true);
- this._dirtyFlag &= ~dirtyFlags.cullingDirty;
- }
- },
-
- _syncStatus: function (parentCmd) {
- // In the visit logic does not restore the _dirtyFlag
- // Because child elements need parent's _dirtyFlag to change himself
- var locFlag = this._dirtyFlag;
-
- var colorDirty = locFlag & dirtyFlags.colorDirty,
- opacityDirty = locFlag & dirtyFlags.opacityDirty;
-
- if (colorDirty)
- //update the color
- this._syncDisplayColor();
-
- if (opacityDirty)
- //update the opacity
- this._syncDisplayOpacity();
-
- if (colorDirty || opacityDirty)
- this._updateColor();
-
- if (locFlag & dirtyFlags.transformDirty) {
- //update the transform
- this.transform(parentCmd);
- }
- else if (locFlag & dirtyFlags.cullingDirty) {
- this.culling(parentCmd);
- }
- }
-};
-
-_ccsg.Node.RenderCmd.prototype.originUpdateTransform = _ccsg.Node.RenderCmd.prototype.updateTransform;
-_ccsg.Node.RenderCmd.prototype.originTransform = _ccsg.Node.RenderCmd.prototype.transform;
-_ccsg.Node.RenderCmd.prototype.originCulling = _ccsg.Node.RenderCmd.prototype.culling;
-_ccsg.Node.RenderCmd.prototype.originUpdateStatus = _ccsg.Node.RenderCmd.prototype.updateStatus;
-_ccsg.Node.RenderCmd.prototype._originSyncStatus = _ccsg.Node.RenderCmd.prototype._syncStatus;
diff --git a/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js b/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js
deleted file mode 100644
index 5c0489e4668..00000000000
--- a/cocos2d/core/base-nodes/CCSGNodeCanvasRenderCmd.js
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
- 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.
- ****************************************************************************/
-
-
-//-----------------------Canvas ---------------------------
-
-//The _ccsg.Node's render command for Canvas
-_ccsg.Node.CanvasRenderCmd = function (renderable) {
- this._ctor(renderable);
-};
-
-var proto = _ccsg.Node.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.RenderCmd.prototype);
-proto.constructor = _ccsg.Node.CanvasRenderCmd;
-proto._rootCtor = _ccsg.Node.CanvasRenderCmd;
-
-proto.detachFromParent = function () {
- var selChildren = this._node._children, item;
- for (var i = 0, len = selChildren.length; i < len; i++) {
- item = selChildren[i];
- if (item && item._renderCmd)
- item._renderCmd.detachFromParent();
- }
-};
-
-proto.setShaderProgram = function (shaderProgram) {
- //do nothing.
-};
-
-proto.getShaderProgram = function () {
- return null;
-};
-
-//util functions
-_ccsg.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc = function (blendFunc) {
- if (!blendFunc)
- return "source-over";
- else {
- if (( blendFunc.src === cc.macro.SRC_ALPHA && blendFunc.dst === cc.macro.ONE) || (blendFunc.src === cc.macro.ONE && blendFunc.dst === cc.macro.ONE))
- return "lighter";
- else if (blendFunc.src === cc.macro.ZERO && blendFunc.dst === cc.macro.SRC_ALPHA)
- return "destination-in";
- else if (blendFunc.src === cc.macro.ZERO && blendFunc.dst === cc.macro.ONE_MINUS_SRC_ALPHA)
- return "destination-out";
- else
- return "source-over";
- }
-};
diff --git a/cocos2d/core/base-nodes/CCSGNodeWebGLRenderCmd.js b/cocos2d/core/base-nodes/CCSGNodeWebGLRenderCmd.js
deleted file mode 100644
index 0eea654e681..00000000000
--- a/cocos2d/core/base-nodes/CCSGNodeWebGLRenderCmd.js
+++ /dev/null
@@ -1,43 +0,0 @@
-/****************************************************************************
- 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 ccsg.Node's render command for WebGL ----------------------------------
-
-_ccsg.Node.WebGLRenderCmd = function (renderable) {
- this._ctor(renderable);
- this._shaderProgram = null;
-};
-
-var proto = _ccsg.Node.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.RenderCmd.prototype);
-proto.constructor = _ccsg.Node.WebGLRenderCmd;
-proto._rootCtor = _ccsg.Node.WebGLRenderCmd;
-
-proto._updateColor = function(){};
-
-proto.setShaderProgram = function (shaderProgram) {
- this._shaderProgram = shaderProgram;
-};
-
-proto.getShaderProgram = function () {
- return this._shaderProgram;
-};
diff --git a/cocos2d/core/components/CCLabelOutline.js b/cocos2d/core/components/CCLabelOutline.js
index 471873d9a7f..752fb146c8c 100644
--- a/cocos2d/core/components/CCLabelOutline.js
+++ b/cocos2d/core/components/CCLabelOutline.js
@@ -44,10 +44,6 @@ var LabelOutline = cc.Class({
requireComponent: cc.Label,
},
- ctor: function() {
- this._labelSGNode = null;
- },
-
properties: {
_color: cc.color(255,255,255,255),
_width: 1,
diff --git a/cocos2d/core/components/CCMask.js b/cocos2d/core/components/CCMask.js
index 44ae3bc13a5..b06f43ba362 100644
--- a/cocos2d/core/components/CCMask.js
+++ b/cocos2d/core/components/CCMask.js
@@ -27,15 +27,17 @@ const renderEngine = require('../renderer/render-engine');
const gfx = renderEngine.gfx;
const StencilMaterial = renderEngine.StencilMaterial;
const RenderComponent = require('./CCRenderComponent');
-const affineTrans = require('../value-types/CCAffineTransform');
-var _trans = affineTrans.make();
+
+const math = require('../renderer/render-engine').math;
+let _mat4_temp = math.mat4.create();
+let _rect_temp = cc.rect();
/**
* !#en the type for mask.
* !#zh 遮罩组件类型
* @enum Mask.Type
*/
-var MaskType = cc.Enum({
+let MaskType = cc.Enum({
/**
* !#en Rect mask.
* !#zh 使用矩形作为遮罩
@@ -65,7 +67,7 @@ const SEGEMENTS_MAX = 10000;
* @class Mask
* @extends Component
*/
-var Mask = cc.Class({
+let Mask = cc.Class({
name: 'cc.Mask',
extends: RenderComponent,
@@ -126,7 +128,7 @@ var Mask = cc.Class({
return this._spriteFrame;
},
set: function (value) {
- var lastSprite = this._spriteFrame;
+ let lastSprite = this._spriteFrame;
if (CC_EDITOR) {
if ((lastSprite && lastSprite._uuid) === (value && value._uuid)) {
return;
@@ -231,7 +233,7 @@ var Mask = cc.Class({
_resizeNodeToTargetNode: CC_EDITOR && function () {
if(this.spriteFrame) {
- var rect = this.spriteFrame.getRect();
+ let rect = this.spriteFrame.getRect();
this.node.setContentSize(rect.width, rect.height);
}
},
@@ -252,7 +254,7 @@ var Mask = cc.Class({
if (oldFrame && oldFrame.off) {
oldFrame.off('load', this._onTextureLoaded, this);
}
- var spriteFrame = this._spriteFrame;
+ let spriteFrame = this._spriteFrame;
if (spriteFrame) {
if (spriteFrame.textureLoaded) {
this._onTextureLoaded(null);
@@ -279,7 +281,7 @@ var Mask = cc.Class({
// Reset material
if (this._type === MaskType.IMAGE_STENCIL) {
- var texture = this.spriteFrame.getTexture();
+ let texture = this.spriteFrame.getTexture();
this._frontMaterial.useTexture = true;
this._frontMaterial.texture = texture.getImpl();
this._frontMaterial.alphaThreshold = this.alphaThreshold;
@@ -294,27 +296,29 @@ var Mask = cc.Class({
},
_hitTest: function (point) {
- var size = this.node.getContentSize(),
- w = size.width,
- h = size.height;
- this.node.getNodeToWorldTransform(_trans);
+ let node = this.node;
+ node.getWorldMatrix(_mat4_temp);
if (this.type === MaskType.RECT || this.type === MaskType.IMAGE_STENCIL) {
- var rect = cc.rect(0, 0, w, h);
- cc._rectApplyAffineTransformIn(rect, _trans);
- var left = point.x - rect.x,
- right = rect.x + rect.width - point.x,
- bottom = point.y - rect.y,
- top = rect.y + rect.height - point.y;
+ let size = node.getContentSize(),
+ w = size.width,
+ h = size.height;
+
+ _rect_temp.x = -node.anchorX * w,
+ _rect_temp.y = -node.anchorX * h;
+ _rect_temp.width = w;
+ _rect_temp.height = h;
+ cc.Rect.transformMat4(_rect_temp, _rect_temp, _mat4_temp);
+
+ let left = point.x - _rect_temp.x,
+ right = _rect_temp.x + _rect_temp.width - point.x,
+ bottom = point.y - _rect_temp.y,
+ top = _rect_temp.y + _rect_temp.height - point.y;
return left >= 0 && right >= 0 && top >= 0 && bottom >= 0;
}
else if (this.type === MaskType.ELLIPSE) {
- var a = w / 2, b = h / 2;
- var cx = _trans.a * a + _trans.c * b + _trans.tx;
- var cy = _trans.b * a + _trans.d * b + _trans.ty;
- var px = point.x - cx, py = point.y - cy;
-
+ let px = point.x - _mat4_temp.m12, py = point.y - _mat4_temp.m13;
return px * px / (a * a) + py * py / (b * b) < 1;
}
},
@@ -324,7 +328,7 @@ var Mask = cc.Class({
this._updateMaterial();
},
- onDisable () {
+ onDestroy () {
this._super();
this._frontMaterial = null;
this._endMaterial = null;
diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js
index 378c7f37f68..2be8a990f7a 100644
--- a/cocos2d/core/components/CCSprite.js
+++ b/cocos2d/core/components/CCSprite.js
@@ -608,13 +608,13 @@ if (CC_EDITOR) {
// override __preload
Sprite.prototype.__superPreload = cc.Component.prototype.__preload;
Sprite.prototype.__preload = function () {
- this.__superPreload();
+ if (this.__superPreload) this.__superPreload();
this.node.on('size-changed', this._resized, this);
};
// override onDestroy
Sprite.prototype.__superOnDestroy = cc.Component.prototype.onDestroy;
Sprite.prototype.onDestroy = function () {
- this.__superOnDestroy();
+ if (this.__superOnDestroy) this.__superOnDestroy();
this.node.off('size-changed', this._resized, this);
};
}
diff --git a/cocos2d/core/components/index.js b/cocos2d/core/components/index.js
index c27624a6d45..00ac275bb8f 100644
--- a/cocos2d/core/components/index.js
+++ b/cocos2d/core/components/index.js
@@ -43,9 +43,9 @@ var components = [
require('./CCPageView'),
require('./CCSlider'),
require('./CCLayout'),
- require('./CCEditBox'),
- require('./CCVideoPlayer'),
- require('./CCWebView'),
+ // require('./CCEditBox'),
+ // require('./CCVideoPlayer'),
+ // require('./CCWebView'),
require('./CCSpriteDistortion'),
require('./CCLabelOutline'),
require('./CCRichText'),
diff --git a/cocos2d/core/index.js b/cocos2d/core/index.js
index 2e5f351c44f..117da12f4ed 100644
--- a/cocos2d/core/index.js
+++ b/cocos2d/core/index.js
@@ -36,7 +36,7 @@ if (!CC_EDITOR || !Editor.isMainProcess) {
// CCIntersection can be used separately.
require('./collider/CCIntersection');
require('./physics');
- require('./camera/CCCamera');
+ // require('./camera/CCCamera');
}
require('./base-ui/CCWidgetManager');
diff --git a/cocos2d/core/predefine.js b/cocos2d/core/predefine.js
index 97a882d52b3..f561a9b78ac 100644
--- a/cocos2d/core/predefine.js
+++ b/cocos2d/core/predefine.js
@@ -35,8 +35,6 @@ require('./platform/CCMacro');
require('./load-pipeline');
require('./textures');
require('./CCDirector');
-require('./CCDirectorWebGL');
-require('./CCDirectorCanvas');
require('./renderer');
if (!(CC_EDITOR && Editor.isMainProcess)) {
diff --git a/cocos2d/core/renderer/render-engine.js b/cocos2d/core/renderer/render-engine.js
index d7cc5d24bcb..68f5399970b 100644
--- a/cocos2d/core/renderer/render-engine.js
+++ b/cocos2d/core/renderer/render-engine.js
@@ -13960,7 +13960,8 @@ module.exports = (function () {
x: 0.0,
y: 0.0,
u: 0.0,
- v: 0.0
+ v: 0.0,
+ color: 0
};
}, 128);
@@ -14023,6 +14024,8 @@ module.exports = (function () {
data._data.length = 0;
data.uvDirty = true;
data.vertDirty = true;
+ data.vertexCount = 0;
+ data.indiceCount = 0;
_pool.free(data);
}
}
diff --git a/cocos2d/core/scenes/CCSGScene.js b/cocos2d/core/scenes/CCSGScene.js
deleted file mode 100644
index 948b4757010..00000000000
--- a/cocos2d/core/scenes/CCSGScene.js
+++ /dev/null
@@ -1,51 +0,0 @@
-/****************************************************************************
- Copyright (c) 2013-2016 Chukong Technologies Inc.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Chukong Aipu reserves all rights not expressly granted to you.
-
- 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.
- ****************************************************************************/
-
-/**
- * ccsg.Scene is a subclass of ccsg.Node that is used only as an abstract concept.
- * ccsg.Scene and ccsg.Node are almost identical with the difference that ccsg.Scene has it's
- * anchor point (by default) at the center of the screen.
- *
- * For the moment ccsg.Scene has no other logic than that, but in future releases it might have
- * additional logic.
- *
- * It is a good practice to use and ccsg.Scene as the parent of all your nodes.
- * @class
- * @extends _ccsg.Node
- * @example
- * var scene = new _ccsg.Scene();
- */
-_ccsg.Scene = _ccsg.Node.extend(/** @lends _ccsg.Scene# */{
- /**
- * Constructor of _ccsg.Scene
- */
- _className:"Scene",
- ctor:function () {
- _ccsg.Node.prototype.ctor.call(this);
- this._ignoreAnchorPointForPosition = true;
- this.setAnchorPoint(0.5, 0.5);
- this.setContentSize(cc.director.getWinSize());
- }
-});
diff --git a/cocos2d/core/sprites/CCSGSprite.js b/cocos2d/core/sprites/CCSGSprite.js
deleted file mode 100644
index dd91b130725..00000000000
--- a/cocos2d/core/sprites/CCSGSprite.js
+++ /dev/null
@@ -1,719 +0,0 @@
-/****************************************************************************
- Copyright (c) 2008-2010 Ricardo Quesada
- 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.
- ****************************************************************************/
-
-var EventTarget = require("../event/event-target");
-var Misc = require('../utils/misc');
-
-/**
- * _ccsg.Sprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) )
- *
- * _ccsg.Sprite can be created with an image, or with a sub-rectangle of an image.
- *
- * If the parent or any of its ancestors is a cc.SpriteBatchNode then the following features/limitations are valid
- * - Features when the parent is a cc.BatchNode:
- * - MUCH faster rendering, specially if the cc.SpriteBatchNode has many children. All the children will be drawn in a single batch.
- *
- * - Limitations
- * - Camera is not supported yet (eg: CCOrbitCamera action doesn't work)
- * - GridBase actions are not supported (eg: CCLens, CCRipple, CCTwirl)
- * - The Alias/Antialias property belongs to CCSpriteBatchNode, so you can't individually set the aliased property.
- * - The Blending function property belongs to CCSpriteBatchNode, so you can't individually set the blending function property.
- * - Parallax scroller is not supported, but can be simulated with a "proxy" sprite.
- *
- * If the parent is an standard ccsg.Node, then _ccsg.Sprite behaves like any other ccsg.Node:
- * - It supports blending functions
- * - It supports aliasing / antialiasing
- * - But the rendering will be slower: 1 draw per children.
- *
- * The default anchorPoint in _ccsg.Sprite is (0.5, 0.5).
- * @class
- * @extends _ccsg.Node
- *
- * @param {String|cc.SpriteFrame|HTMLImageElement|cc.Texture2D} fileName The string which indicates a path to image file, e.g., "scene1/monster.png".
- * @param {Rect} rect Only the contents inside rect of pszFileName's texture will be applied for this sprite.
- * @param {Boolean} [rotated] Whether or not the texture rectangle is rotated.
- * @example
- *
- * 1.Create a sprite with image path and rect
- * var sprite1 = new _ccsg.Sprite("res/HelloHTML5World.png");
- * var sprite2 = new _ccsg.Sprite("res/HelloHTML5World.png",cc.rect(0,0,480,320));
- *
- * 2.Create a sprite with a sprite frame
- * var sprite = new _ccsg.Sprite(spriteFrame);
- *
- * 3.Create a sprite with an existing texture contained in a CCTexture2D object
- * After creation, the rect will be the size of the texture, and the offset will be (0,0).
- * var texture = cc.textureUtils.addImage("HelloHTML5World.png");
- * var sprite1 = new _ccsg.Sprite(texture);
- * var sprite2 = new _ccsg.Sprite(texture, cc.rect(0,0,480,320));
- *
- * @property {Boolean} dirty - Indicates whether the sprite needs to be updated.
- * @property {Boolean} flippedX - Indicates whether or not the sprite is flipped on x axis.
- * @property {Boolean} flippedY - Indicates whether or not the sprite is flipped on y axis.
- * @property {Number} offsetX - <@readonly> The offset position on x axis of the sprite in texture. Calculated automatically by editors like Zwoptex.
- * @property {Number} offsetY - <@readonly> The offset position on x axis of the sprite in texture. Calculated automatically by editors like Zwoptex.
- * @property {Texture2D} texture - Texture used to render the sprite.
- * @property {Boolean} textureRectRotated - <@readonly> Indicate whether the texture rectangle is rotated.
- * @property {cc.SpriteBatchNode} batchNode - The batch node object if this sprite is rendered by cc.SpriteBatchNode.
- * @property {cc.V3F_C4B_T2F_Quad} quad - <@readonly> The quad (tex coords, vertex coords and color) information.
- */
-_ccsg.Sprite = _ccsg.Node.extend({
- dirty:false,
-
- _recursiveDirty:null, //Whether all of the sprite's children needs to be updated
- _shouldBeHidden:false, //should not be drawn because one of the ancestors is not visible
- _transformToBatch:null,
-
- //
- // Data used when the sprite is self-rendered
- //
- _blendFunc:null, //It's required for CCTextureProtocol inheritance
- _texture:null, //cc.Texture2D object that is used to render the sprite
-
- //
- // Shared data
- //
- // texture
- _rect:null, //Rectangle of cc.Texture2D
- _rectRotated:false, //Whether the texture is rotated
-
- // Offset Position (used by Zwoptex)
- _offsetPosition:null, // absolute
- _unflippedOffsetPositionFromCenter:null,
-
- _opacityModifyRGB:false,
-
- // image is flipped
- _flippedX:false, //Whether the sprite is flipped horizontally or not.
- _flippedY:false, //Whether the sprite is flipped vertically or not.
-
- _textureLoaded:false,
- _className:"Sprite",
-
- ctor: function (fileName, rect, rotated) {
- var self = this;
- _ccsg.Node.prototype.ctor.call(self);
- EventTarget.call(self);
-
- self._shouldBeHidden = false;
- self._offsetPosition = cc.p(0, 0);
- self._unflippedOffsetPositionFromCenter = cc.p(0, 0);
- self._blendFunc = {src: cc.macro.BLEND_SRC, dst: cc.macro.BLEND_DST};
- self._rect = cc.rect(0, 0, 0, 0);
-
- self._softInit(fileName, rect, rotated);
- },
-
- /**
- * Returns whether the texture have been loaded
- * @returns {boolean}
- */
- textureLoaded:function(){
- return this._textureLoaded;
- },
-
- /**
- * Add a event listener for texture loaded event.
- * @param {Function} callback
- * @param {Object} target
- * @deprecated since 3.1, please use EventTarget instead
- */
- addLoadedEventListener:function(callback, target){
- this.once("load", callback, target);
- },
-
- /**
- * Returns whether or not the Sprite needs to be updated in the Atlas
- * @return {Boolean} True if the sprite needs to be updated in the Atlas, false otherwise.
- */
- isDirty:function () {
- return this.dirty;
- },
-
- /**
- * Makes the sprite to be updated in the Atlas.
- * @param {Boolean} bDirty
- */
- setDirty:function (bDirty) {
- this.dirty = bDirty;
- },
-
- /**
- * Returns whether or not the texture rectangle is rotated.
- * @return {Boolean}
- */
- isTextureRectRotated:function () {
- return this._rectRotated;
- },
-
- /**
- * Returns the rect of the _ccsg.Sprite in points
- * @return {Rect}
- */
- getTextureRect:function () {
- return cc.rect(this._rect);
- },
-
- /**
- * Returns the offset position of the sprite. Calculated automatically by editors like Zwoptex.
- * @return {cc.Vec2}
- */
- getOffsetPosition:function () {
- return cc.p(this._offsetPosition);
- },
-
- _getOffsetX: function () {
- return this._offsetPosition.x;
- },
- _getOffsetY: function () {
- return this._offsetPosition.y;
- },
-
- /**
- * Returns the blend function
- * @return {cc.BlendFunc}
- */
- getBlendFunc:function () {
- return this._blendFunc;
- },
-
- /**
- * Initializes a sprite with a SpriteFrame. The texture and rect in SpriteFrame will be applied on this sprite.
- * Please pass parameters to the constructor to initialize the sprite, do not call this function yourself,
- * @param {cc.SpriteFrame} spriteFrame A CCSpriteFrame object. It should includes a valid texture and a rect
- * @return {Boolean} true if the sprite is initialized properly, false otherwise.
- */
- initWithSpriteFrame:function (spriteFrame) {
- cc.assertID(spriteFrame, 2606);
-
- if(!spriteFrame.textureLoaded()){
- //add event listener
- this._textureLoaded = false;
- spriteFrame.once("load", this._renderCmd._spriteFrameLoadedCallback, this._renderCmd);
- }
-
- //TODO
- var rotated = cc._renderType === cc.game.RENDER_TYPE_CANVAS ? false : spriteFrame._rotated;
- var ret = this.initWithTexture(spriteFrame.getTexture(), spriteFrame.getRect(), rotated);
- this.setSpriteFrame(spriteFrame);
-
- return ret;
- },
-
- /**
- * Initializes a sprite with a sprite frame name.
- * A cc.SpriteFrame will be fetched from the cc.SpriteFrameCache by name.
- * If the cc.SpriteFrame doesn't exist it will raise an exception.
- * Please pass parameters to the constructor to initialize the sprite, do not call this function yourself.
- * @param {String} spriteFrameName A key string that can fected a valid cc.SpriteFrame from cc.SpriteFrameCache
- * @return {Boolean} true if the sprite is initialized properly, false otherwise.
- * @deprecated
- */
- initWithSpriteFrameName:function () {
- cc.warnID(2608);
- return;
- },
-
- /**
- *
- * set the vertex rect.
- * It will be called internally by setTextureRect.
- * Useful if you want to create 2x images from SD images in Retina Display.
- * Do not call it manually. Use setTextureRect instead.
- * (override this method to generate "double scale" sprites)
- *
- * @param {Rect} rect
- */
- setVertexRect:function (rect) {
- var locRect = this._rect;
- locRect.x = rect.x;
- locRect.y = rect.y;
- locRect.width = rect.width;
- locRect.height = rect.height;
- },
-
- //
- // _ccsg.Node property overloads
- //
-
- /**
- * Sets whether the sprite should be flipped horizontally or not.
- * @param {Boolean} flippedX true if the sprite should be flipped horizontally, false otherwise.
- */
- setFlippedX:function (flippedX) {
- if (this._flippedX !== flippedX) {
- this._flippedX = flippedX;
- this.setTextureRect(this._rect, this._rectRotated, this._contentSize);
- this.setNodeDirty(true);
- }
- },
-
- /**
- * Sets whether the sprite should be flipped vertically or not.
- * @param {Boolean} flippedY true if the sprite should be flipped vertically, false otherwise.
- */
- setFlippedY:function (flippedY) {
- if (this._flippedY !== flippedY) {
- this._flippedY = flippedY;
- this.setTextureRect(this._rect, this._rectRotated, this._contentSize);
- this.setNodeDirty(true);
- }
- },
-
- /**
- *
- * Returns the flag which indicates whether the sprite is flipped horizontally or not.
- *
- * It only flips the texture of the sprite, and not the texture of the sprite's children.
- * Also, flipping the texture doesn't alter the anchorPoint.
- * If you want to flip the anchorPoint too, and/or to flip the children too use:
- * sprite.setScaleX(sprite.getScaleX() * -1);
- * @return {Boolean} true if the sprite is flipped horizontally, false otherwise.
- */
- isFlippedX:function () {
- return this._flippedX;
- },
-
- /**
- *
- * Return the flag which indicates whether the sprite is flipped vertically or not.
- *
- * It only flips the texture of the sprite, and not the texture of the sprite's children.
- * Also, flipping the texture doesn't alter the anchorPoint.
- * If you want to flip the anchorPoint too, and/or to flip the children too use:
- * sprite.setScaleY(sprite.getScaleY() * -1);
- * @return {Boolean} true if the sprite is flipped vertically, false otherwise.
- */
- isFlippedY:function () {
- return this._flippedY;
- },
-
- //
- // RGBA protocol
- //
- /**
- * Sets whether opacity modify color or not.
- * @function
- * @param {Boolean} modify
- */
- setOpacityModifyRGB: function (modify) {
- if (this._opacityModifyRGB !== modify) {
- this._opacityModifyRGB = modify;
- this._renderCmd._setColorDirty();
- }
- },
-
- /**
- * Returns whether opacity modify color or not.
- * @return {Boolean}
- */
- isOpacityModifyRGB:function () {
- return this._opacityModifyRGB;
- },
-
- // Animation
-
- /**
- * Changes the display frame with animation name and index.
- * The animation name will be get from the CCAnimationCache
- * @param {String} animationName
- * @param {Number} frameIndex
- */
- setDisplayFrameWithAnimationName:function (animationName, frameIndex) {
- cc.assertID(animationName, 2610);
-
- var cache = cc.spriteFrameAnimationCache.getAnimation(animationName);
- if(!cache){
- cc.logID(2602);
- return;
- }
- var animFrame = cache.getFrames()[frameIndex];
- if(!animFrame){
- cc.logID(2603);
- return;
- }
- this.setSpriteFrame(animFrame.getSpriteFrame());
- },
-
- // CCTextureProtocol
- /**
- * Returns the texture of the sprite node
- * @returns {Texture2D}
- */
- getTexture:function () {
- return this._texture;
- },
-
- _softInit: function (fileName, rect, rotated) {
- if (fileName === undefined)
- _ccsg.Sprite.prototype.init.call(this);
- else if (cc.js.isString(fileName)) {
- if (fileName[0] === "#") {
- cc.logID(2728, fileName);
- } else {
- // Init with filename and rect
- _ccsg.Sprite.prototype.init.call(this, fileName, rect);
- }
- } else if (typeof fileName === "object") {
- if (fileName instanceof cc.Texture2D) {
- // Init with texture and rect
- this.initWithTexture(fileName, rect, rotated);
- } else if (fileName instanceof cc.SpriteFrame) {
- // Init with a sprite frame
- this.initWithSpriteFrame(fileName);
- } else if ((fileName instanceof HTMLImageElement) || (fileName instanceof HTMLCanvasElement)) {
- // Init with a canvas or image element
- var texture2d = new cc.Texture2D();
- texture2d.initWithElement(fileName);
- texture2d.handleLoadedTexture();
- this.initWithTexture(texture2d);
- }
- }
- },
-
- /**
- * Returns the quad (tex coords, vertex coords and color) information.
- * @return {cc.V3F_C4B_T2F_Quad|null} Returns a cc.V3F_C4B_T2F_Quad object when render mode is WebGL, returns null when render mode is Canvas.
- */
- getQuad:function () {
- return null;
- },
-
- /**
- * conforms to cc.TextureProtocol protocol
- * @function
- * @param {Number|cc.BlendFunc} src
- * @param {Number} dst
- */
- setBlendFunc: function (src, dst) {
- var locBlendFunc = this._blendFunc;
- if (dst === undefined) {
- locBlendFunc.src = src.src;
- locBlendFunc.dst = src.dst;
- } else {
- locBlendFunc.src = src;
- locBlendFunc.dst = dst;
- }
- this._renderCmd.updateBlendFunc(locBlendFunc);
- },
-
- /**
- * Initializes an empty sprite with nothing init.
- * Please pass parameters to the constructor to initialize the sprite, do not call this function yourself.
- * @function
- * @return {Boolean}
- */
- init: function () {
- var _t = this;
- if (arguments.length > 0)
- return _t.initWithFile(arguments[0], arguments[1]);
-
- _t.dirty = _t._recursiveDirty = false;
-
- _t._blendFunc.src = cc.macro.BLEND_SRC;
- _t._blendFunc.dst = cc.macro.BLEND_DST;
-
- _t.texture = null;
- _t._flippedX = _t._flippedY = false;
-
- // default transform anchor: center
- _t.anchorX = 0.5;
- _t.anchorY = 0.5;
-
- // zwoptex default values
- _t._offsetPosition.x = 0;
- _t._offsetPosition.y = 0;
-
- // updated in "useSelfRender"
- // Atlas: TexCoords
- _t.setTextureRect(cc.rect(0, 0, 0, 0), false, cc.size(0, 0));
- return true;
- },
-
- /**
- *
- * Initializes a sprite with an image filename.
- *
- * This method will find pszFilename from local file system, load its content to CCTexture2D,
- * then use CCTexture2D to create a sprite.
- * After initialization, the rect used will be the size of the image. The offset will be (0,0).
- * Please pass parameters to the constructor to initialize the sprite, do not call this function yourself.
- *
- * @param {String} filename The path to an image file in local file system
- * @param {Rect} rect The rectangle assigned the content area from texture.
- * @return {Boolean} true if the sprite is initialized properly, false otherwise.
- */
- initWithFile:function (filename, rect) {
- cc.assertID(filename, 2609);
- if (!rect) {
- rect = cc.rect(0, 0, tex.width, tex.height);
- }
-
- var tex = cc.loader.getRes(filename);
- if (!tex) {
- tex = cc.textureUtil.addImage(filename);
- return this.initWithTexture(tex, rect);
- } else {
- return this.initWithTexture(tex, rect);
- }
- },
-
- /**
- * Initializes a sprite with a texture and a rect in points, optionally rotated.
- * After initialization, the rect used will be the size of the texture, and the offset will be (0,0).
- * Please pass parameters to the constructor to initialize the sprite, do not call this function yourself.
- * @function
- * @param {cc.Texture2D|HTMLImageElement|HTMLCanvasElement} texture A pointer to an existing CCTexture2D object. You can use a CCTexture2D object for many sprites.
- * @param {Rect} [rect] Only the contents inside rect of this texture will be applied for this sprite.
- * @param {Boolean} [rotated] Whether or not the texture rectangle is rotated.
- * @param {Boolean} [counterclockwise=true] Whether or not the texture rectangle rotation is counterclockwise (texture package is counterclockwise, spine is clockwise).
- * @return {Boolean} true if the sprite is initialized properly, false otherwise.
- */
- initWithTexture: function (texture, rect, rotated, counterclockwise) {
- var _t = this;
- cc.assertID(arguments.length !== 0, 2710);
-
- rotated = rotated || false;
- texture = this._renderCmd._handleTextureForRotatedTexture(texture, rect, rotated, counterclockwise);
-
- _t._recursiveDirty = false;
- _t.dirty = false;
- _t._opacityModifyRGB = true;
-
- _t._blendFunc.src = cc.macro.BLEND_SRC;
- _t._blendFunc.dst = cc.macro.BLEND_DST;
-
- _t._flippedX = _t._flippedY = false;
-
- // default transform anchor: center
- _t.setAnchorPoint(0.5, 0.5);
-
- // zwoptex default values
- _t._offsetPosition.x = 0;
- _t._offsetPosition.y = 0;
-
- var locTextureLoaded = texture.loaded;
- _t._textureLoaded = locTextureLoaded;
-
- if (!locTextureLoaded) {
- _t._rectRotated = rotated;
- if (rect) {
- _t._rect.x = rect.x;
- _t._rect.y = rect.y;
- _t._rect.width = rect.width;
- _t._rect.height = rect.height;
- }
- if(_t.texture)
- _t.texture.off("load", _t._renderCmd._textureLoadedCallback, _t._renderCmd);
- texture.once("load", _t._renderCmd._textureLoadedCallback, _t._renderCmd);
- _t.setTexture(texture);
- return true;
- }
-
- if (!rect)
- rect = cc.rect(0, 0, texture.width, texture.height);
-
- this._renderCmd._checkTextureBoundary(texture, rect, rotated);
-
- _t.setTexture(texture);
- _t.setTextureRect(rect, rotated);
- this.emit("load");
- return true;
- },
-
- /**
- * Updates the texture rect of the CCSprite in points.
- * @function
- * @param {Rect} rect a rect of texture
- * @param {Boolean} [rotated] Whether or not the texture is rotated
- * @param {Size} [untrimmedSize] The original pixels size of the texture
- * @param {Boolean} [needConvert] contentScaleFactor switch
- */
- setTextureRect: function (rect, rotated, untrimmedSize, needConvert) {
- var _t = this;
- _t._rectRotated = rotated || false;
- _t.setContentSize(untrimmedSize || rect);
-
- _t.setVertexRect(rect);
- _t._renderCmd._setTextureCoords(rect, needConvert);
-
- var relativeOffsetX = _t._unflippedOffsetPositionFromCenter.x, relativeOffsetY = _t._unflippedOffsetPositionFromCenter.y;
- if (_t._flippedX)
- relativeOffsetX = -relativeOffsetX;
- if (_t._flippedY)
- relativeOffsetY = -relativeOffsetY;
- var locRect = _t._rect;
- _t._offsetPosition.x = relativeOffsetX + (_t._contentSize.width - locRect.width) / 2;
- _t._offsetPosition.y = relativeOffsetY + (_t._contentSize.height - locRect.height) / 2;
- },
-
- // Frames
- /**
- * Sets a new sprite frame to the sprite.
- * @function
- * @param {cc.SpriteFrame} newFrame
- */
- setSpriteFrame: function (newFrame) {
- var _t = this;
- cc.assertID(newFrame, 2712);
-
- this.setNodeDirty(true);
-
- var frameOffset = newFrame.getOffset();
- _t._unflippedOffsetPositionFromCenter.x = frameOffset.x;
- _t._unflippedOffsetPositionFromCenter.y = frameOffset.y;
-
- // update rect
- var pNewTexture = newFrame.getTexture();
- var locTextureLoaded = newFrame.textureLoaded();
- if (!locTextureLoaded) {
- _t._textureLoaded = false;
- newFrame.once("load", function (event) {
- var sender = event.currentTarget;
- _t._textureLoaded = true;
- var locNewTexture = sender.getTexture();
- if (locNewTexture !== _t._texture)
- _t._setTexture(locNewTexture);
- _t.setTextureRect(sender.getRect(), sender.isRotated(), sender.getOriginalSize());
- _t.emit("load");
- _t.setColor(_t._realColor);
- }, _t);
- } else {
- _t._textureLoaded = true;
- // update texture before updating texture rect
- if (pNewTexture !== _t._texture) {
- _t._setTexture(pNewTexture);
- _t.setColor(_t._realColor);
- }
- _t.setTextureRect(newFrame.getRect(), newFrame.isRotated(), newFrame.getOriginalSize());
- }
- this._renderCmd._updateForSetSpriteFrame(pNewTexture);
- },
-
- /**
- * Sets a new display frame to the sprite.
- * @param {cc.SpriteFrame|String} newFrame
- * @deprecated
- */
- setDisplayFrame: function(newFrame){
- cc.logID(2604);
- this.setSpriteFrame(newFrame);
- },
-
- /**
- * Returns whether or not a cc.SpriteFrame is being displayed
- * @function
- * @param {cc.SpriteFrame} frame
- * @return {Boolean}
- */
- isFrameDisplayed: function(frame){
- return this._renderCmd.isFrameDisplayed(frame);
- },
-
- /**
- * Returns the current displayed frame.
- * @deprecated since 3.4, please use getSpriteFrame instead
- * @return {cc.SpriteFrame}
- */
- displayFrame: function () {
- return this.getSpriteFrame();
- },
-
- /**
- * Returns the current displayed frame.
- * @return {cc.SpriteFrame}
- */
- getSpriteFrame: function () {
- return new cc.SpriteFrame(this._texture,
- this._rect,
- this._rectRotated,
- this._unflippedOffsetPositionFromCenter,
- this._contentSize);
- },
-
- // CCTextureProtocol
- /**
- * Sets the texture of sprite
- * @function
- * @param {cc.Texture2D|String} texture
- */
- setTexture: function (texture) {
- if(!texture)
- return this._renderCmd._setTexture(null);
-
- //CCSprite.cpp 327 and 338
- var isFileName = cc.js.isString(texture);
-
- if(isFileName)
- texture = cc.textureUtil.loadImage(texture);
-
- if(texture.loaded){
- this._setTexture(texture, isFileName);
- this.setColor(this._realColor);
- this._textureLoaded = true;
- this.emit("load");
- }else{
- this._renderCmd._setTexture(texture);
- texture.once("load", function (event) {
- this._setTexture(texture, isFileName);
- this.setColor(this._realColor);
- this._textureLoaded = true;
- this.emit("load");
- }, this);
- }
- },
-
- _setTexture: function(texture, change){
- this._renderCmd._setTexture(texture);
- if(change)
- this._changeRectWithTexture(texture);
- },
-
- _changeRectWithTexture: function(texture) {
- var rect = cc.rect(0, 0, texture.width, texture.height);
- this.setTextureRect(rect);
- },
-
- _createRenderCmd: function(){
- if(cc._renderType === cc.game.RENDER_TYPE_CANVAS)
- return new _ccsg.Sprite.CanvasRenderCmd(this);
- else
- return new _ccsg.Sprite.WebGLRenderCmd(this);
- }
-});
-
-cc.js.addon(_ccsg.Sprite.prototype, EventTarget.prototype);
-
-var SameNameGetSets = ['opacity', 'color', 'texture', 'quad'];
-var DiffNameGetSets = {
- opacityModifyRGB: ['isOpacityModifyRGB', 'setOpacityModifyRGB'],
- flippedX: ['isFlippedX', 'setFlippedX'],
- flippedY: ['isFlippedY', 'setFlippedY'],
- offsetX: ['_getOffsetX'],
- offsetY: ['_getOffsetY'],
- textureRectRotated: ['isTextureRectRotated'],
-};
-Misc.propertyDefine(_ccsg.Sprite, SameNameGetSets, DiffNameGetSets);
diff --git a/cocos2d/core/sprites/CCSGSpriteCanvasRenderCmd.js b/cocos2d/core/sprites/CCSGSpriteCanvasRenderCmd.js
deleted file mode 100644
index a455fa1ceb1..00000000000
--- a/cocos2d/core/sprites/CCSGSpriteCanvasRenderCmd.js
+++ /dev/null
@@ -1,256 +0,0 @@
-/****************************************************************************
- 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.
- ****************************************************************************/
-
-_ccsg.Sprite.CanvasRenderCmd = function (renderable) {
- this._rootCtor(renderable);
- this._needDraw = true;
- this._textureCoord = {
- renderX: 0, //the x of texture coordinate for render, when texture tinted, its value doesn't equal x.
- renderY: 0, //the y of texture coordinate for render, when texture tinted, its value doesn't equal y.
- x: 0, //the x of texture coordinate for node.
- y: 0, //the y of texture coordinate for node.
- width: 0,
- height: 0,
- validRect: false
- };
- this._blendFuncStr = "source-over";
- this._colorized = false;
-
- this._textureToRender = null;
-};
-
-var proto = _ccsg.Sprite.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
-proto.constructor = _ccsg.Sprite.CanvasRenderCmd;
-
-proto.setDirtyRecursively = function (value) {};
-
-proto._setTexture = function (texture) {
- var node = this._node;
- if (node._texture !== texture) {
- node._textureLoaded = texture ? texture.loaded : false;
- node._texture = texture;
- var rect = cc.rect(0, 0, texture.width, texture.height);
- node.setTextureRect(rect);
- this._updateColor();
- }
-};
-
-proto._setColorDirty = function () {
- this.setDirtyFlag(_ccsg.Node._dirtyFlags.colorDirty | _ccsg.Node._dirtyFlags.opacityDirty);
-};
-
-proto.isFrameDisplayed = function (frame) { //TODO there maybe has a bug
- var node = this._node;
- if (frame.getTexture() !== node._texture)
- return false;
- return cc.rectEqualToRect(frame.getRect(), node._rect);
-};
-
-proto.updateBlendFunc = function (blendFunc) {
- this._blendFuncStr = _ccsg.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc(blendFunc);
-};
-
-proto._handleTextureForRotatedTexture = function (texture, rect, rotated, counterclockwise) {
- if (rotated && texture.isLoaded()) {
- var tempElement = texture.getHtmlElementObj();
- tempElement = _ccsg.Sprite.CanvasRenderCmd._cutRotateImageToCanvas(tempElement, rect, counterclockwise);
- var tempTexture = new cc.Texture2D();
- tempTexture.initWithElement(tempElement);
- tempTexture.handleLoadedTexture();
- texture = tempTexture;
- rect.x = rect.y = 0;
- this._node._rect = cc.rect(0, 0, rect.width, rect.height);
- }
- return texture;
-};
-
-proto._checkTextureBoundary = function (texture, rect, rotated) {
- if (texture && texture.url) {
- var _x = rect.x + rect.width, _y = rect.y + rect.height;
- if (_x > texture.width)
- cc.errorID(3300, texture.url);
- if (_y > texture.height)
- cc.errorID(3400, texture.url);
- }
-};
-
-proto.rendering = function (ctx, scaleX, scaleY) {
- var node = this._node;
- var locTextureCoord = this._textureCoord, alpha = (this._displayedOpacity / 255);
-
- var texture = this._textureToRender || node._texture;
-
- if ((texture && (locTextureCoord.width === 0 || locTextureCoord.height === 0|| !texture.loaded)) || alpha === 0)
- return;
-
- var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
- var locX = node._offsetPosition.x, locHeight = node._rect.height, locWidth = node._rect.width,
- locY = -node._offsetPosition.y - locHeight, image;
-
- wrapper.setTransform(this._worldTransform, scaleX, scaleY);
- wrapper.setCompositeOperation(this._blendFuncStr);
- wrapper.setGlobalAlpha(alpha);
-
- if(node._flippedX || node._flippedY)
- wrapper.save();
- if (node._flippedX) {
- locX = -locX - locWidth;
- context.scale(-1, 1);
- }
- if (node._flippedY) {
- locY = node._offsetPosition.y;
- context.scale(1, -1);
- }
-
- var sx, sy, sw, sh, x, y, w, h;
- if (this._colorized) {
- sx = 0;
- sy = 0;
- }else{
- sx = locTextureCoord.renderX;
- sy = locTextureCoord.renderY;
- }
- sw = locTextureCoord.width;
- sh = locTextureCoord.height;
-
- x = locX;
- y = locY;
- w = locWidth;
- h = locHeight;
-
- if (texture&& texture._image) {
- image = texture._image;
- if (texture._pattern !== "") {
- wrapper.setFillStyle(context.createPattern(image, texture._pattern));
- context.fillRect(x, y, w, h);
- } else {
- context.drawImage(image,
- sx, sy, sw, sh,
- x, y, w, h);
- }
- } else {
- var contentSize = node._contentSize;
- if (locTextureCoord.validRect) {
- var curColor = this._displayedColor;
- wrapper.setFillStyle("rgba(" + curColor.r + "," + curColor.g + "," + curColor.b + ",1)");
- context.fillRect(x, y, contentSize.width, contentSize.height);
- }
- }
- if(node._flippedX || node._flippedY)
- wrapper.restore();
- cc.g_NumberOfDraws++;
-};
-
-proto._updateColor = function(){
- var node = this._node;
-
- var texture = node._texture, rect = this._textureCoord;
- var dColor = this._displayedColor;
-
- if(texture){
- if(dColor.r !== 255 || dColor.g !== 255 || dColor.b !== 255){
- this._textureToRender = texture._generateColorTexture(dColor.r, dColor.g, dColor.b, rect);
- this._colorized = true;
- }else if(texture){
- this._textureToRender = texture;
- this._colorized = false;
- }
- }
-};
-
-proto._updateForSetSpriteFrame = function (pNewTexture, textureLoaded){
- this._colorized = false;
- this._textureCoord.renderX = this._textureCoord.x;
- this._textureCoord.renderY = this._textureCoord.y;
- textureLoaded = textureLoaded || pNewTexture.loaded;
- if (textureLoaded) {
- var curColor = this._node.getColor();
- if (curColor.r !== 255 || curColor.g !== 255 || curColor.b !== 255)
- this._updateColor();
- }
-};
-
-proto._spriteFrameLoadedCallback = function (event) {
- var node = this._node, spriteFrame = event.currentTarget;
- node.setTextureRect(spriteFrame.getRect(), spriteFrame.isRotated(), spriteFrame.getOriginalSize());
-
- this._updateColor();
- node.emit("load");
-};
-
-proto._textureLoadedCallback = function (event) {
- var node = this._node, sender = event.currentTarget;
- if (node._textureLoaded)
- return;
-
- node._textureLoaded = true;
- var locRect = node._rect;
- if (!locRect) {
- locRect = cc.rect(0, 0, sender.width, sender.height);
- } else if (cc._rectEqualToZero(locRect)) {
- locRect.width = sender.width;
- locRect.height = sender.height;
- }
-
- node.texture = sender;
- node.setTextureRect(locRect, node._rectRotated);
-
- //set the texture's color after the it loaded
- var locColor = this._displayedColor;
- if (locColor.r !== 255 || locColor.g !== 255 || locColor.b !== 255)
- this._updateColor();
-
- node.emit("load");
-};
-
-proto._setTextureCoords = function (rect) {
- var locTextureRect = this._textureCoord;
- locTextureRect.renderX = locTextureRect.x = 0 | rect.x;
- locTextureRect.renderY = locTextureRect.y = 0 | rect.y;
- locTextureRect.width = 0 | rect.width;
- locTextureRect.height = 0 | rect.height;
- locTextureRect.validRect = !(locTextureRect.width === 0 || locTextureRect.height === 0 || locTextureRect.x < 0 || locTextureRect.y < 0);
-};
-
-_ccsg.Sprite.CanvasRenderCmd._cutRotateImageToCanvas = function (texture, rect, counterclockwise) {
- if (!texture)
- return null;
-
- if (!rect)
- return texture;
-
- counterclockwise = counterclockwise == null? true: counterclockwise; // texture package is counterclockwise, spine is clockwise
-
- var nCanvas = document.createElement("canvas");
- nCanvas.width = rect.width;
- nCanvas.height = rect.height;
- var ctx = nCanvas.getContext("2d");
- ctx.translate(nCanvas.width / 2, nCanvas.height / 2);
- if(counterclockwise)
- ctx.rotate(-1.5707963267948966);
- else
- ctx.rotate(1.5707963267948966);
- ctx.drawImage(texture, rect.x, rect.y, rect.height, rect.width, -rect.height / 2, -rect.width / 2, rect.height, rect.width);
- return nCanvas;
-};
diff --git a/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js b/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js
deleted file mode 100644
index d78f86c5ef1..00000000000
--- a/cocos2d/core/sprites/CCSGSpriteWebGLRenderCmd.js
+++ /dev/null
@@ -1,295 +0,0 @@
-/****************************************************************************
- 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.
- ****************************************************************************/
-
-var macro = cc.macro;
-
-//Sprite's WebGL render command
-_ccsg.Sprite.WebGLRenderCmd = function (renderable) {
- this._rootCtor(renderable);
- this._needDraw = true;
-
- this._vertices = [
- {x: 0, y: 0, u: 0, v: 0}, // tl
- {x: 0, y: 0, u: 0, v: 0}, // bl
- {x: 0, y: 0, u: 0, v: 0}, // tr
- {x: 0, y: 0, u: 0, v: 0} // br
- ];
- this._dirty = false;
- this._recursiveDirty = false;
-
- this._shaderProgram = cc.shaderCache.programForKey(macro.SHADER_SPRITE_POSITION_TEXTURECOLOR);
-};
-
-var proto = _ccsg.Sprite.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
-proto.constructor = _ccsg.Sprite.WebGLRenderCmd;
-
-proto.updateBlendFunc = function (blendFunc) {};
-
-proto.setDirtyFlag = function(dirtyFlag){
- _ccsg.Node.WebGLRenderCmd.prototype.setDirtyFlag.call(this, dirtyFlag);
- this._dirty = true;
-};
-
-proto.setDirtyRecursively = function (value) {
- this._recursiveDirty = value;
- this._dirty = value;
- // recursively set dirty
- var locChildren = this._node._children, child, l = locChildren ? locChildren.length : 0;
- for (var i = 0; i < l; i++) {
- child = locChildren[i];
- (child instanceof _ccsg.Sprite) && child._renderCmd.setDirtyRecursively(value);
- }
-};
-
-proto._handleTextureForRotatedTexture = function (texture) {
- return texture;
-};
-
-proto.isFrameDisplayed = function (frame) {
- var node = this._node;
- return (cc.rectEqualToRect(frame.getRect(), node._rect) && frame.getTexture().url === node._texture.url
- && cc.pointEqualToPoint(frame.getOffset(), node._unflippedOffsetPositionFromCenter));
-};
-
-proto._updateForSetSpriteFrame = function () {};
-
-proto._spriteFrameLoadedCallback = function (event) {
- var spriteFrame = event.currentTarget;
- this._node.setTextureRect(spriteFrame.getRect(), spriteFrame.isRotated(), spriteFrame.getOriginalSize());
- this._node.emit("load");
-};
-
-proto._textureLoadedCallback = function (event) {
- var node = this._node, sender = event.currentTarget;
- if (node._textureLoaded)
- return;
-
- node._textureLoaded = true;
- var locRect = node._rect;
- if (!locRect) {
- locRect = cc.rect(0, 0, sender.width, sender.height);
- } else if (cc._rectEqualToZero(locRect)) {
- locRect.width = sender.width;
- locRect.height = sender.height;
- }
-
- node.texture = sender;
- node.setTextureRect(locRect, node._rectRotated);
-
- node.emit("load");
-
- // Force refresh the render command list
- cc.renderer.childrenOrderDirty = true;
-};
-
-proto._setTextureCoords = function (rect) {
- var node = this._node;
-
- var tex = node._texture;
- var uvs = this._vertices;
- if (!tex)
- return;
-
- var atlasWidth = tex.pixelWidth;
- var atlasHeight = tex.pixelHeight;
-
- var left, right, top, bottom, tempSwap;
- if (node._rectRotated) {
- if (macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) {
- left = (2 * rect.x + 1) / (2 * atlasWidth);
- right = left + (rect.height * 2 - 2) / (2 * atlasWidth);
- top = (2 * rect.y + 1) / (2 * atlasHeight);
- bottom = top + (rect.width * 2 - 2) / (2 * atlasHeight);
- } else {
- left = rect.x / atlasWidth;
- right = (rect.x + rect.height) / atlasWidth;
- top = rect.y / atlasHeight;
- bottom = (rect.y + rect.width) / atlasHeight;
- }
-
- if (node._flippedX) {
- tempSwap = top;
- top = bottom;
- bottom = tempSwap;
- }
-
- if (node._flippedY) {
- tempSwap = left;
- left = right;
- right = tempSwap;
- }
-
- uvs[0].u = right; // tl
- uvs[0].v = top; // tl
- uvs[1].u = left; // bl
- uvs[1].v = top; // bl
- uvs[2].u = right; // tr
- uvs[2].v = bottom; // tr
- uvs[3].u = left; // br
- uvs[3].v = bottom; // br
- } else {
- if (macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL) {
- left = (2 * rect.x + 1) / (2 * atlasWidth);
- right = left + (rect.width * 2 - 2) / (2 * atlasWidth);
- top = (2 * rect.y + 1) / (2 * atlasHeight);
- bottom = top + (rect.height * 2 - 2) / (2 * atlasHeight);
- } else {
- left = rect.x / atlasWidth;
- right = (rect.x + rect.width) / atlasWidth;
- top = rect.y / atlasHeight;
- bottom = (rect.y + rect.height) / atlasHeight;
- }
-
- if (node._flippedX) {
- tempSwap = left;
- left = right;
- right = tempSwap;
- }
-
- if (node._flippedY) {
- tempSwap = top;
- top = bottom;
- bottom = tempSwap;
- }
-
- uvs[0].u = left; // tl
- uvs[0].v = top; // tl
- uvs[1].u = left; // bl
- uvs[1].v = bottom; // bl
- uvs[2].u = right; // tr
- uvs[2].v = top; // tr
- uvs[3].u = right; // br
- uvs[3].v = bottom; // br
- }
-};
-
-proto._setColorDirty = function () {};
-
-proto._updateBlendFunc = function () {
- // it's possible to have an untextured sprite
- var node = this._node;
- if (!node._texture || !node._texture.hasPremultipliedAlpha()) {
- node._blendFunc.src = macro.SRC_ALPHA;
- node._blendFunc.dst = macro.ONE_MINUS_SRC_ALPHA;
- node.opacityModifyRGB = false;
- } else {
- node._blendFunc.src = macro.BLEND_SRC;
- node._blendFunc.dst = macro.BLEND_DST;
- node.opacityModifyRGB = true;
- }
-};
-
-proto._setTexture = function (texture) {
- var node = this._node;
-
- if(node._texture !== texture){
- node._textureLoaded = texture ? texture.loaded : false;
- node._texture = texture;
- this._updateBlendFunc();
-
- if (node._textureLoaded) {
- // Force refresh the render command list
- cc.renderer.childrenOrderDirty = true;
- }
- }
-};
-
-proto._checkTextureBoundary = function (texture, rect, rotated) {
- if (texture && texture.url) {
- var _x, _y;
- if (rotated) {
- _x = rect.x + rect.height;
- _y = rect.y + rect.width;
- } else {
- _x = rect.x + rect.width;
- _y = rect.y + rect.height;
- }
- if (_x > texture.width) {
- cc.errorID(3300, texture.url);
- }
- if (_y > texture.height) {
- cc.errorID(3400, texture.url);
- }
- }
-};
-
-proto.transform = function (parentCmd, recursive) {
- this.originTransform(parentCmd, recursive);
-
- var node = this._node,
- lx = node._offsetPosition.x, rx = lx + node._rect.width,
- by = node._offsetPosition.y, ty = by + node._rect.height,
- wt = this._worldTransform;
-
- var vertices = this._vertices;
- vertices[0].x = lx * wt.a + ty * wt.c + wt.tx; // tl
- vertices[0].y = lx * wt.b + ty * wt.d + wt.ty;
- vertices[1].x = lx * wt.a + by * wt.c + wt.tx; // bl
- vertices[1].y = lx * wt.b + by * wt.d + wt.ty;
- vertices[2].x = rx * wt.a + ty * wt.c + wt.tx; // tr
- vertices[2].y = rx * wt.b + ty * wt.d + wt.ty;
- vertices[3].x = rx * wt.a + by * wt.c + wt.tx; // br
- vertices[3].y = rx * wt.b + by * wt.d + wt.ty;
-};
-
-proto.needDraw = function () {
- var node = this._node, locTexture = node._texture;
- return (this._needDraw && locTexture);
-};
-
-proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset) {
- var node = this._node, locTexture = node._texture;
- if (!(locTexture && locTexture.loaded && node._rect.width && node._rect.height) || !this._displayedOpacity)
- return 0;
-
- // Fill in vertex data with quad information (4 vertices for sprite)
- var opacity = this._displayedOpacity;
- var color, colorVal = this._displayedColor._val;
- if (node._opacityModifyRGB) {
- var a = opacity / 255,
- r = this._displayedColor.r * a,
- g = this._displayedColor.g * a,
- b = this._displayedColor.b * a;
- color = ((opacity<<24) >>> 0) + (b<<16) + (g<<8) + r;
- }
- else {
- color = ((opacity<<24) >>> 0) + ((colorVal&0xff00)<<8) + ((colorVal&0xff0000)>>8) + (colorVal>>>24);
- }
- var z = node._vertexZ;
-
- var vertices = this._vertices;
- var i, len = vertices.length, vertex, offset = vertexDataOffset;
- for (i = 0; i < len; ++i) {
- vertex = vertices[i];
- f32buffer[offset] = vertex.x;
- f32buffer[offset + 1] = vertex.y;
- f32buffer[offset + 2] = z;
- ui32buffer[offset + 3] = color;
- f32buffer[offset + 4] = vertex.u;
- f32buffer[offset + 5] = vertex.v;
- offset += 6;
- }
-
- return len;
-};
diff --git a/cocos2d/core/sprites/CCScale9Sprite.js b/cocos2d/core/sprites/CCScale9Sprite.js
deleted file mode 100644
index 09eaa8a9536..00000000000
--- a/cocos2d/core/sprites/CCScale9Sprite.js
+++ /dev/null
@@ -1,1561 +0,0 @@
-/****************************************************************************
- Copyright (c) 2016 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.
- ****************************************************************************/
-
-var EventTarget = require("../event/event-target");
-
-function sortIndex (a, b) {
- return a - b;
-};
-
-var dataPool = {
- _pool: {},
- _lengths: [],
- put: function (data) {
- var length = data.length;
- if (!this._pool[length]) {
- this._pool[length] = [data];
- this._lengths.push(length);
- this._lengths.sort(sortIndex);
- }
- else {
- this._pool[length].push(data);
- }
- },
- get: function (length) {
- var id;
- for (var i = 0; i < this._lengths.length; i++) {
- if (this._lengths[i] >= length) {
- id = this._lengths[i];
- break;
- }
- }
- if (id) {
- return this._pool[id].pop();
- }
- else {
- return undefined;
- }
- }
-};
-
-var macro = cc.macro,
- webgl,
- vl, vb, vt, vr;
-
-/*
- *
- * A 9-slice sprite for cocos2d UI.
- *
- * 9-slice scaling allows you to specify how scaling is applied
- * to specific areas of a sprite. With 9-slice scaling (3x3 grid),
- * you can ensure that the sprite does not become distorted when
- * scaled.
- * @note: it will refactor in v3.1
- * @see http://yannickloriot.com/library/ios/cccontrolextension/Classes/CCScale9Sprite.html
- *
- * @class
- * @extends _ccsg.Node
- *
- * @property {Size} preferredSize - The preferred size of the 9-slice sprite
- * @property {Rect} capInsets - The cap insets of the 9-slice sprite
- * @property {Number} insetLeft - The left inset of the 9-slice sprite
- * @property {Number} insetTop - The top inset of the 9-slice sprite
- * @property {Number} insetRight - The right inset of the 9-slice sprite
- * @property {Number} insetBottom - The bottom inset of the 9-slice sprite
- */
-var simpleQuadGenerator = {
- _rebuildQuads_base: function (sprite) {
- var spriteFrame = sprite._spriteFrame,
- contentSize = sprite._contentSize,
- isTrimmedContentSize = sprite._isTrimmedContentSize;
-
- //build vertices
- var vertices = sprite._vertices,
- corner = sprite._corner,
- l, b, r, t;
- if (isTrimmedContentSize) {
- l = 0;
- b = 0;
- r = contentSize.width;
- t = contentSize.height;
- } else {
- var originalSize = spriteFrame._originalSize;
- var rect = spriteFrame._rect;
- var offset = spriteFrame._offset;
-
- var cw = contentSize.width, ch = contentSize.height;
- var ow = originalSize.width, oh = originalSize.height;
- var rw = rect.width, rh = rect.height;
-
- var scaleX = cw / ow;
- var scaleY = ch / oh;
- var trimmLeft = offset.x + (ow - rw) / 2;
- var trimmRight = offset.x - (ow - rw) / 2;
- var trimmedBottom = offset.y + (oh - rh) / 2;
- var trimmedTop = offset.y - (oh - rh) / 2;
-
- l = trimmLeft * scaleX;
- b = trimmedBottom * scaleY;
- r = cw + trimmRight * scaleX;
- t = ch + trimmedTop * scaleY;
- }
-
- if (vertices.length < 8) {
- dataPool.put(vertices);
- vertices = dataPool.get(8) || new Float32Array(8);
- sprite._vertices = vertices;
- }
- // bl, br, tl, tr
- if (webgl) {
- var wt = sprite._renderCmd._worldTransform;
- var wta = wt.a, wtb = wt.b, wtc = wt.c, wtd = wt.d, wtx = wt.tx, wty = wt.ty;
-
- var la = l * wta, lb = l * wtb, ra = r * wta, rb = r * wtb,
- tcx = t * wtc + wtx, tdy = t * wtd + wty,
- bcx = b * wtc + wtx, bdy = b * wtd + wty;
- vertices[0] = la + bcx;
- vertices[1] = lb + bdy;
- vertices[2] = ra + bcx;
- vertices[3] = rb + bdy;
- vertices[4] = la + tcx;
- vertices[5] = lb + tdy;
- vertices[6] = ra + tcx;
- vertices[7] = rb + tdy;
- }
- else {
- vertices[0] = l;
- vertices[1] = b;
- vertices[2] = r;
- vertices[3] = b;
- vertices[4] = l;
- vertices[5] = t;
- vertices[6] = r;
- vertices[7] = t;
- }
-
- corner[0] = 0; // bl
- corner[1] = 2; // br
- corner[2] = 4; // tl
- corner[3] = 6; // tr
-
- //build uvs
- if (sprite._uvsDirty) {
- this._calculateUVs(sprite, spriteFrame);
- }
-
- sprite._vertCount = 4;
- },
-
- _calculateUVs: function (sprite, spriteFrame) {
- var uvs = sprite._uvs;
- var atlasWidth = spriteFrame._texture.width;
- var atlasHeight = spriteFrame._texture.height;
- var textureRect = spriteFrame._rect;
-
- if (uvs.length < 8) {
- dataPool.put(uvs);
- uvs = dataPool.get(8) || new Float32Array(8);
- sprite._uvs = uvs;
- }
-
- //uv computation should take spritesheet into account.
- var l, b, r, t;
- var texelCorrect = macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL ? 0.5 : 0;
-
- if (spriteFrame._rotated) {
- l = (textureRect.x + texelCorrect) / atlasWidth;
- b = (textureRect.y + textureRect.width - texelCorrect) / atlasHeight;
- r = (textureRect.x + textureRect.height - texelCorrect) / atlasWidth;
- t = (textureRect.y + texelCorrect) / atlasHeight;
- uvs[0] = l; uvs[1] = t;
- uvs[2] = l; uvs[3] = b;
- uvs[4] = r; uvs[5] = t;
- uvs[6] = r; uvs[7] = b;
- }
- else {
- l = (textureRect.x + texelCorrect) / atlasWidth;
- b = (textureRect.y + textureRect.height - texelCorrect) / atlasHeight;
- r = (textureRect.x + textureRect.width - texelCorrect) / atlasWidth;
- t = (textureRect.y + texelCorrect) / atlasHeight;
- uvs[0] = l; uvs[1] = b;
- uvs[2] = r; uvs[3] = b;
- uvs[4] = l; uvs[5] = t;
- uvs[6] = r; uvs[7] = t;
- }
- }
-};
-
-var scale9QuadGenerator = {
- x: new Array(4),
- y: new Array(4),
- _rebuildQuads_base: function (sprite) {
- var spriteFrame = sprite._spriteFrame,
- contentSize = sprite._contentSize,
- insetLeft = sprite._insetLeft,
- insetRight = sprite._insetRight,
- insetTop = sprite._insetTop,
- insetBottom = sprite._insetBottom;
-
- //build vertices
- var vertices = sprite._vertices;
- var wt = sprite._renderCmd._worldTransform;
- var leftWidth, centerWidth, rightWidth;
- var topHeight, centerHeight, bottomHeight;
- var rect = spriteFrame._rect;
- var corner = sprite._corner;
-
- leftWidth = insetLeft;
- rightWidth = insetRight;
- centerWidth = rect.width - leftWidth - rightWidth;
- topHeight = insetTop;
- bottomHeight = insetBottom;
- centerHeight = rect.height - topHeight - bottomHeight;
-
- var preferSize = contentSize;
- var sizableWidth = preferSize.width - leftWidth - rightWidth;
- var sizableHeight = preferSize.height - topHeight - bottomHeight;
- var xScale = preferSize.width / (leftWidth + rightWidth);
- var yScale = preferSize.height / (topHeight + bottomHeight);
- xScale = (isNaN(xScale) || xScale > 1) ? 1 : xScale;
- yScale = (isNaN(yScale) || yScale > 1) ? 1 : yScale;
- sizableWidth = sizableWidth < 0 ? 0 : sizableWidth;
- sizableHeight = sizableHeight < 0 ? 0 : sizableHeight;
- var x = this.x;
- var y = this.y;
- x[0] = 0;
- x[1] = leftWidth * xScale;
- x[2] = x[1] + sizableWidth;
- x[3] = preferSize.width;
- y[0] = 0;
- y[1] = bottomHeight * yScale;
- y[2] = y[1] + sizableHeight;
- y[3] = preferSize.height;
-
- if (vertices.length < 32) {
- dataPool.put(vertices);
- vertices = dataPool.get(32) || new Float32Array(32);
- sprite._vertices = vertices;
- }
- var offset = 0, row, col;
- if (webgl) {
- for (row = 0; row < 4; row++) {
- for (col = 0; col < 4; col++) {
- vertices[offset] = x[col] * wt.a + y[row] * wt.c + wt.tx;
- vertices[offset+1] = x[col] * wt.b + y[row] * wt.d + wt.ty;
- offset += 2;
- }
- }
- }
- else {
- for (row = 0; row < 4; row++) {
- for (col = 0; col < 4; col++) {
- vertices[offset] = x[col];
- vertices[offset+1] = y[row];
- offset += 2;
- }
- }
- }
-
- corner[0] = 0; // bl
- corner[1] = 6; // br
- corner[2] = 24; // tl
- corner[3] = 30; // tr
-
- //build uvs
- if (sprite._uvsDirty) {
- this._calculateUVs(sprite, spriteFrame, insetLeft, insetRight, insetTop, insetBottom);
- }
- },
-
- _calculateUVs: function (sprite, spriteFrame, insetLeft, insetRight, insetTop, insetBottom) {
- var uvs = sprite._uvs;
- var rect = spriteFrame._rect;
- var atlasWidth = spriteFrame._texture.width;
- var atlasHeight = spriteFrame._texture.height;
-
- //caculate texture coordinate
- var leftWidth, centerWidth, rightWidth;
- var topHeight, centerHeight, bottomHeight;
- var textureRect = spriteFrame._rect;
-
- leftWidth = insetLeft;
- rightWidth = insetRight;
- centerWidth = rect.width - leftWidth - rightWidth;
- topHeight = insetTop;
- bottomHeight = insetBottom;
- centerHeight = rect.height - topHeight - bottomHeight;
-
- if (uvs.length < 32) {
- dataPool.put(uvs);
- uvs = dataPool.get(32) || new Float32Array(32);
- sprite._uvs = uvs;
- }
-
- //uv computation should take spritesheet into account.
- var u = this.x;
- var v = this.y;
- var texelCorrect = macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL ? 0.5 : 0;
- var offset = 0, row, col;
-
- if (spriteFrame._rotated) {
- u[0] = (textureRect.x + texelCorrect) / atlasWidth;
- u[1] = (bottomHeight + textureRect.x) / atlasWidth;
- u[2] = (bottomHeight + centerHeight + textureRect.x) / atlasWidth;
- u[3] = (textureRect.x + textureRect.height - texelCorrect) / atlasWidth;
-
- v[3] = (textureRect.y + texelCorrect) / atlasHeight;
- v[2] = (leftWidth + textureRect.y) / atlasHeight;
- v[1] = (leftWidth + centerWidth + textureRect.y) / atlasHeight;
- v[0] = (textureRect.y + textureRect.width - texelCorrect) / atlasHeight;
-
- for (row = 0; row < 4; row++) {
- for (col = 0; col < 4; col++) {
- uvs[offset] = u[row];
- uvs[offset+1] = v[3-col];
- offset += 2;
- }
- }
- }
- else {
- u[0] = (textureRect.x + texelCorrect) / atlasWidth;
- u[1] = (leftWidth + textureRect.x) / atlasWidth;
- u[2] = (leftWidth + centerWidth + textureRect.x) / atlasWidth;
- u[3] = (textureRect.x + textureRect.width - texelCorrect) / atlasWidth;
-
- v[3] = (textureRect.y + texelCorrect) / atlasHeight;
- v[2] = (topHeight + textureRect.y) / atlasHeight;
- v[1] = (topHeight + centerHeight + textureRect.y) / atlasHeight;
- v[0] = (textureRect.y + textureRect.height - texelCorrect) / atlasHeight;
-
- for (row = 0; row < 4; row++) {
- for (col = 0; col < 4; col++) {
- uvs[offset] = u[col];
- uvs[offset+1] = v[row];
- offset += 2;
- }
- }
- }
- }
-};
-
-var tiledQuadGenerator = {
- _rebuildQuads_base: function (sprite, spriteFrame, contentSize) {
-
- var spriteFrame = sprite._spriteFrame,
- contentSize = sprite._contentSize,
- vertices = sprite._vertices,
- corner = sprite._corner,
- wt = sprite._renderCmd._worldTransform,
- uvs = sprite._uvs;
- //build uvs
- var atlasWidth = spriteFrame._texture.width;
- var atlasHeight = spriteFrame._texture.height;
- var textureRect = spriteFrame._rect;
-
- //uv computation should take spritesheet into account.
- var u0, v0, u1, v1;
- var texelCorrect = macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL ? 0.5 : 0;
- if (spriteFrame._rotated) {
- u0 = (textureRect.x + texelCorrect) / atlasWidth;
- u1 = (textureRect.x + textureRect.height - texelCorrect) / atlasWidth;
- v0 = (textureRect.y + textureRect.width - texelCorrect) / atlasHeight;
- v1 = (textureRect.y + texelCorrect) / atlasHeight;
- }
- else {
- u0 = (textureRect.x + texelCorrect) / atlasWidth;
- u1 = (textureRect.x + textureRect.width - texelCorrect) / atlasWidth;
- v0 = (textureRect.y + textureRect.height - texelCorrect) / atlasHeight;
- v1 = (textureRect.y + texelCorrect) / atlasHeight;
- }
-
- //build quads
- var rectWidth = textureRect.width;
- var rectHeight = textureRect.height;
- var hRepeat = contentSize.width / rectWidth;
- var vRepeat = contentSize.height / rectHeight;
- var row = Math.ceil(vRepeat), col = Math.ceil(hRepeat);
-
- if (row * col > (65536 / 4)) {
- cc.errorID(2625);
- }
- var dataLength = row * col * 4 * 2;
- if (vertices.length < dataLength) {
- dataPool.put(vertices);
- vertices = dataPool.get(dataLength) || new Float32Array(dataLength);
- sprite._vertices = vertices;
- }
- if (uvs.length < dataLength) {
- dataPool.put(uvs);
- uvs = dataPool.get(dataLength) || new Float32Array(dataLength);
- sprite._uvs = uvs;
- }
-
- var offset = 0, l, b, r, t;
- sprite._vertCount = 0;
- for (var vindex = 0; vindex < row; ++vindex) {
- for (var hindex = 0; hindex < col; ++hindex) {
- l = rectWidth * hindex;
- b = rectHeight * vindex;
- r = rectWidth * Math.min(hindex + 1, hRepeat);
- t = rectHeight * Math.min(vindex + 1, vRepeat);
- // bl.x, bl.y, br.x, br.y, tl.x, tl.y, tr.x, tr.y
- if (webgl) {
- var la = l * wt.a, lb = l * wt.b, ra = r * wt.a, rb = r * wt.b,
- tcx = t * wt.c + wt.tx, tdy = t * wt.d + wt.ty,
- bcx = b * wt.c + wt.tx, bdy = b * wt.d + wt.ty;
- vertices[offset] = la + bcx;
- vertices[offset + 1] = lb + bdy;
- vertices[offset + 2] = ra + bcx;
- vertices[offset + 3] = rb + bdy;
- vertices[offset + 4] = la + tcx;
- vertices[offset + 5] = lb + tdy;
- vertices[offset + 6] = ra + tcx;
- vertices[offset + 7] = rb + tdy;
- }
- else {
- vertices[offset] = l;
- vertices[offset + 1] = b;
- vertices[offset + 2] = r;
- vertices[offset + 3] = b;
- vertices[offset + 4] = l;
- vertices[offset + 5] = t;
- vertices[offset + 6] = r;
- vertices[offset + 7] = t;
- }
-
- if (!spriteFrame._rotated) {
- uvs[offset] = u0;
- uvs[offset + 1] = v0;
- uvs[offset + 2] = r = u0 + (u1 - u0) * Math.min(1, hRepeat - hindex);
- uvs[offset + 3] = v0;
- uvs[offset + 4] = u0;
- uvs[offset + 5] = t = v0 + (v1 - v0) * Math.min(1, vRepeat - vindex);
- uvs[offset + 6] = r;
- uvs[offset + 7] = t;
- } else {
- uvs[offset] = u0;
- uvs[offset + 1] = v1;
- uvs[offset + 2] = u0;
- uvs[offset + 3] = t = v1 + (v0 - v1) * Math.min(1, hRepeat - hindex);
- uvs[offset + 4] = r = u0 + (u1 - u0) * Math.min(1, vRepeat - vindex);
- uvs[offset + 5] = v1;
- uvs[offset + 6] = r;
- uvs[offset + 7] = t;
- }
- offset += 8;
- sprite._vertCount += 4;
- if (offset > dataLength) return;
- }
- }
-
- corner[0] = 0; // bl
- corner[1] = (col-1) * 8 + 2; // br
- corner[2] = (row-1) * col * 8 + 4; // tl
- corner[3] = dataLength - 2; // tr
- }
-};
-
-var fillQuadGeneratorBar = {
- //percentage from 0 to 1;
- _rebuildQuads_base : function (sprite) {
- var spriteFrame = sprite._spriteFrame,
- contentSize = sprite._contentSize;
-
- var fillStart = sprite._fillStart;
- var fillRange = sprite._fillRange;
-
- if (fillRange < 0) {
- fillStart += fillRange;
- fillRange = -fillRange;
- }
-
- fillRange = fillStart + fillRange;
- fillStart = fillStart > 1.0 ? 1.0 : fillStart;
- fillStart = fillStart < 0.0 ? 0.0 : fillStart;
-
- fillRange = fillRange > 1.0 ? 1.0 : fillRange;
- fillRange = fillRange < 0.0 ? 0.0 : fillRange;
- fillRange = fillRange - fillStart;
-
- var fillType = sprite._fillType;
-
- var vertices = sprite._vertices,
- corner = sprite._corner,
- wt = sprite._renderCmd._worldTransform,
- uvs = sprite._uvs;
- var fillEnd;
- //build vertices
- var l = 0, b = 0,
- r = contentSize.width, t = contentSize.height;
- //build uvs
- var atlasWidth = spriteFrame._texture.width;
- var atlasHeight = spriteFrame._texture.height;
- var textureRect = spriteFrame._rect;
- //uv computation should take spritesheet into account.
- var ul, vb, ur, vt;
- var texelCorrect = macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL ? 0.5 : 0;
- if (spriteFrame._rotated) {
- ul = (textureRect.x + texelCorrect) / atlasWidth;
- vb = (textureRect.y + textureRect.width - texelCorrect) / atlasHeight;
- ur = (textureRect.x + textureRect.height - texelCorrect) / atlasWidth;
- vt = (textureRect.y + texelCorrect) / atlasHeight;
- }
- else {
- ul = (textureRect.x + texelCorrect) / atlasWidth;
- vb = (textureRect.y + textureRect.height - texelCorrect) / atlasHeight;
- ur = (textureRect.x + textureRect.width - texelCorrect) / atlasWidth;
- vt = (textureRect.y + texelCorrect) / atlasHeight;
- }
-
- if (vertices.length < 8) {
- dataPool.put(vertices);
- vertices = dataPool.get(8) || new Float32Array(8);
- sprite._vertices = vertices;
- }
- if (uvs.length < 8) {
- dataPool.put(uvs);
- uvs = dataPool.get(8) || new Float32Array(8);
- sprite._uvs = uvs;
- }
-
- var quadUV = new Array(8);
- if (!spriteFrame._rotated) {
- quadUV[0] = quadUV[4] = ul;
- quadUV[2] = quadUV[6] = ur;
- quadUV[1] = quadUV[3] = vb;
- quadUV[5] = quadUV[7] = vt;
- } else {
- quadUV[0] = quadUV[2] = ul;
- quadUV[4] = quadUV[6] = ur;
- quadUV[3] = quadUV[7] = vb;
- quadUV[1] = quadUV[5] = vt;
- }
-
- //do clamp
- fillStart = fillStart > 1 ? 1 : fillStart;
- fillStart = fillStart < 0 ? 0 : fillStart;
- fillRange = fillRange < 0 ? 0 : fillRange;
- fillEnd = fillStart + fillRange;
- fillEnd = fillEnd > 1 ? 1 : fillEnd;
-
- // bl : 0, 1
- // br : 2, 3
- // tl : 4, 5
- // tr : 6, 7
- var progressStart, progressEnd;
- switch (fillType) {
- case FillType.HORIZONTAL:
- progressStart = l + (r - l) * fillStart;
- progressEnd = l + (r - l) * fillEnd;
-
- l = progressStart;
- r = progressEnd;
-
- uvs[0] = quadUV[0] + (quadUV[2] - quadUV[0]) * fillStart;
- uvs[1] = quadUV[1];
- uvs[2] = quadUV[0] + (quadUV[2] - quadUV[0]) * fillEnd;
- uvs[3] = quadUV[3];
- uvs[4] = quadUV[4] + (quadUV[6] - quadUV[4]) * fillStart;
- uvs[5] = quadUV[5];
- uvs[6] = quadUV[4] + (quadUV[6] - quadUV[4]) * fillEnd;
- uvs[7] = quadUV[7];
- break;
- case FillType.VERTICAL:
- progressStart = b + (t - b) * fillStart;
- progressEnd = b + (t - b) * fillEnd;
-
- b = progressStart;
- t = progressEnd;
-
- uvs[0] = quadUV[0];
- uvs[1] = quadUV[1] + (quadUV[5] - quadUV[1]) * fillStart;
- uvs[2] = quadUV[2];
- uvs[3] = quadUV[3] + (quadUV[7] - quadUV[3]) * fillStart;
- uvs[4] = quadUV[4];
- uvs[5] = quadUV[1] + (quadUV[5] - quadUV[1]) * fillEnd;
- uvs[6] = quadUV[6];
- uvs[7] = quadUV[3] + (quadUV[7] - quadUV[3]) * fillEnd;
- break;
- default:
- cc.errorID(2626);
- break;
- }
-
- //build vertices
- if (webgl) {
- var la = l * wt.a, lb = l * wt.b, ra = r * wt.a, rb = r * wt.b,
- tcx = t * wt.c + wt.tx, tdy = t * wt.d + wt.ty,
- bcx = b * wt.c + wt.tx, bdy = b * wt.d + wt.ty;
- vertices[0] = la + bcx;
- vertices[1] = lb + bdy;
- vertices[2] = ra + bcx;
- vertices[3] = rb + bdy;
- vertices[4] = la + tcx;
- vertices[5] = lb + tdy;
- vertices[6] = ra + tcx;
- vertices[7] = rb + tdy;
- } else{
- vertices[0] = l;
- vertices[1] = b;
- vertices[2] = r;
- vertices[3] = b;
- vertices[4] = l;
- vertices[5] = t;
- vertices[6] = r;
- vertices[7] = t;
- }
-
- sprite._vertCount = 4;
-
- corner[0] = 0; // bl
- corner[1] = 2; // br
- corner[2] = 4; // tl
- corner[3] = 6; // tr
- }
-};
-
-var fillQuadGeneratorRadial = {
- _vertPos: [cc.v2(0, 0), cc.v2(0, 0), cc.v2(0, 0), cc.v2(0, 0)],
- _vertices: [cc.v2(0,0),cc.v2(0,0)],
- _uvs: [cc.v2(0,0),cc.v2(0,0)],
- _intersectPoint_1: [cc.v2(0, 0), cc.v2(0, 0), cc.v2(0, 0), cc.v2(0, 0)],
- _intersectPoint_2: [cc.v2(0, 0), cc.v2(0, 0), cc.v2(0, 0), cc.v2(0, 0)],
- outVerts: null,
- outUvs: null,
- rawVerts: null,
- rawUvs: null,
-
- _rebuildQuads_base : function (sprite) {
- var spriteFrame = sprite._spriteFrame,
- contentSize = sprite._contentSize;
-
- var fillStart = sprite._fillStart;
- var fillRange = sprite._fillRange;
- if (fillRange < 0) {
- fillStart += fillRange;
- fillRange = -fillRange;
- }
-
- sprite._isTriangle = true;
- if (!sprite._rawVerts) {
- sprite._rawVerts = dataPool.get(8) || new Float32Array(8);
- sprite._rawUvs = dataPool.get(8) || new Float32Array(8);
- }
-
- var fillCenter = sprite._fillCenter;
-
- var vertices = sprite._vertices,
- corner = sprite._corner,
- uvs = sprite._uvs,
- rawVerts = sprite._rawVerts,
- rawUvs = sprite._rawUvs,
- wt = sprite._renderCmd._worldTransform;
- //do round fill start [0,1), include 0, exclude 1
- while (fillStart >= 1.0) fillStart -= 1.0;
- while (fillStart < 0.0) fillStart += 1.0;
- var cx = fillCenter.x * contentSize.width,
- cy = fillCenter.y * contentSize.height;
- var center = cc.v2( cx, cy);
-
- fillStart *= Math.PI * 2;
- fillRange *= Math.PI * 2;
- var fillEnd = fillStart + fillRange;
-
- this.outVerts = vertices;
- this.outUvs = uvs;
- this.rawVerts = rawVerts;
- this.rawUvs = rawUvs;
-
- //build vertices
- this._calculateVertices(wt, spriteFrame, contentSize);
- //build uvs
- this._calculateUVs(spriteFrame);
-
- var _vertPos = this._vertPos,
- _vertices = this._vertices;
-
- _vertPos[0].x = _vertPos[3].x = _vertices[0].x;
- _vertPos[1].x = _vertPos[2].x = _vertices[1].x;
- _vertPos[0].y = _vertPos[1].y = _vertices[0].y;
- _vertPos[2].y = _vertPos[3].y = _vertices[1].y;
-
- //fallback
- //todo remove it if outside is implemented
- if(center.x > _vertices[1].x) {
- center.x = _vertices[1].x;
- }
- if(center.x < _vertices[0].x) {
- center.x = _vertices[0].x;
- }
- if(center.y < _vertices[0].y) {
- center.y = _vertices[0].y;
- }
- if(center.y > _vertices[1].y) {
- center.y = _vertices[1].y;
- }
-
- rawVerts[0] = rawVerts[4] = this._vertices[0].x;
- rawVerts[2] = rawVerts[6] = this._vertices[1].x;
- rawVerts[1] = rawVerts[3] = this._vertices[0].y;
- rawVerts[5] = rawVerts[7] = this._vertices[1].y;
-
- if (!spriteFrame._rotated) {
- rawUvs[0] = rawUvs[4] = this._uvs[0].x;
- rawUvs[2] = rawUvs[6] = this._uvs[1].x;
- rawUvs[1] = rawUvs[3] = this._uvs[0].y;
- rawUvs[5] = rawUvs[7] = this._uvs[1].y;
- } else {
- rawUvs[0] = rawUvs[2] = this._uvs[0].x;
- rawUvs[4] = rawUvs[6] = this._uvs[1].x;
- rawUvs[3] = rawUvs[7] = this._uvs[0].y;
- rawUvs[1] = rawUvs[5] = this._uvs[1].y;
- }
-
- var triangles = [null, null, null, null];
- if(center.x !== this._vertices[0].x) {
- triangles[0] = [3, 0];
- }
- if(center.x !== this._vertices[1].x) {
- triangles[2] = [1, 2];
- }
- if(center.y !== this._vertices[0].y) {
- triangles[1] = [0, 1];
- }
- if(center.y !== this._vertices[1].y) {
- triangles[3] = [2, 3];
- }
-
- this._getInsectedPoints(this._vertices[0].x, this._vertices[1].x, this._vertices[0].y, this._vertices[1].y, center, fillStart, this._intersectPoint_1);
- this._getInsectedPoints(this._vertices[0].x, this._vertices[1].x, this._vertices[0].y, this._vertices[1].y, center, fillStart + fillRange, this._intersectPoint_2);
-
- var dataLength = 3 * 5 * 2;
- if (vertices.length < dataLength) {
- dataPool.put(vertices);
- vertices = dataPool.get(dataLength) || new Float32Array(dataLength);
- this.outVerts = sprite._vertices = vertices;
- }
- if (uvs.length < dataLength) {
- dataPool.put(uvs);
- uvs = dataPool.get(dataLength) || new Float32Array(dataLength);
- this.outUvs = sprite._uvs = uvs;
- }
-
- var offset = 0, count = 0;
- for(var triangleIndex = 0; triangleIndex < 4; ++triangleIndex) {
- var triangle = triangles[triangleIndex];
- if(triangle === null) {
- continue;
- }
- //all in
- if(fillRange >= Math.PI * 2) {
- this._generateTriangle(wt, offset, center, this._vertPos[triangle[0]], this._vertPos[triangle[1]]);
- offset += 6;
- count += 3;
- continue;
- }
- //test against
- var startAngle = this._getVertAngle(center, this._vertPos[triangle[0]]);
- var endAngle = this._getVertAngle(center, this._vertPos[triangle[1]]);
- if(endAngle < startAngle) endAngle += Math.PI * 2;
- startAngle -= Math.PI * 2;
- endAngle -= Math.PI * 2;
- //testing
- for(var testIndex = 0; testIndex < 3; ++testIndex) {
- if(startAngle >= fillEnd) {
- //all out
- } else if (startAngle >= fillStart) {
- if(endAngle >= fillEnd) {
- //startAngle to fillEnd
- this._generateTriangle(wt, offset, center, this._vertPos[triangle[0]], this._intersectPoint_2[triangleIndex]);
- } else {
- //startAngle to endAngle
- this._generateTriangle(wt, offset, center, this._vertPos[triangle[0]], this._vertPos[triangle[1]]);
- }
- offset += 6;
- count += 3;
- } else {
- //startAngle < fillStart
- if(endAngle <= fillStart) {
- //all out
- } else if(endAngle <= fillEnd) {
- //fillStart to endAngle
- this._generateTriangle(wt, offset, center, this._intersectPoint_1[triangleIndex], this._vertPos[triangle[1]]);
- offset += 6;
- count += 3;
- } else {
- //fillStart to fillEnd
- this._generateTriangle(wt, offset, center, this._intersectPoint_1[triangleIndex], this._intersectPoint_2[triangleIndex]);
- offset += 6;
- count += 3;
- }
- }
- //add 2 * PI
- startAngle += Math.PI * 2;
- endAngle += Math.PI * 2;
- }
- }
- sprite._vertCount = count;
-
- var minx = Infinity, miny = Infinity, maxx = -Infinity, maxy = -Infinity;
- var x, y;
- for (var i = 0, l = offset; i < l; i+=2) {
- x = vertices[i];
- y = vertices[i+1];
- if (x <= minx) {
- minx = x;
- corner[0] = i;
- }
- else if (x >= maxx) {
- maxx = x;
- corner[1] = i;
- }
-
- if (y <= miny) {
- miny = y;
- corner[2] = i;
- }
- else if (y >= maxy) {
- maxy = y;
- corner[3] = i;
- }
- }
- },
-
- _generateTriangle: function(wt, offset, vert0, vert1, vert2) {
- var rawVerts = this.rawVerts;
- var rawUvs = this.rawUvs;
- var vertices = this.outVerts;
- var v0x = rawVerts[0];
- var v0y = rawVerts[1];
- var v1x = rawVerts[6];
- var v1y = rawVerts[7];
- var progressX, progressY;
- // tl: 0, 1
- // bl: 2, 3
- // tr: 4, 5
- if(webgl) {
- vertices[offset] = vert0.x * wt.a + vert0.y * wt.c + wt.tx;
- vertices[offset+1] = vert0.x * wt.b + vert0.y * wt.d + wt.ty;
- vertices[offset+2] = vert1.x * wt.a + vert1.y * wt.c + wt.tx;
- vertices[offset+3] = vert1.x * wt.b + vert1.y * wt.d + wt.ty;
- vertices[offset+4] = vert2.x * wt.a + vert2.y * wt.c + wt.tx;
- vertices[offset+5] = vert2.x * wt.b + vert2.y * wt.d + wt.ty;
-
- } else {
- vertices[offset] = vert0.x;
- vertices[offset+1] = vert0.y;
- vertices[offset+2] = vert1.x;
- vertices[offset+3] = vert1.y;
- vertices[offset+4] = vert2.x;
- vertices[offset+5] = vert2.y;
- }
-
- progressX = (vert0.x - v0x) / (v1x - v0x);
- progressY = (vert0.y - v0y) / (v1y - v0y);
- this._generateUV(progressX, progressY, rawUvs, offset);
-
- progressX = (vert1.x - v0x) / (v1x - v0x);
- progressY = (vert1.y - v0y) / (v1y - v0y);
- this._generateUV(progressX, progressY, rawUvs, offset + 2);
-
- progressX = (vert2.x - v0x) / (v1x - v0x);
- progressY = (vert2.y - v0y) / (v1y - v0y);
- this._generateUV(progressX, progressY, rawUvs, offset + 4);
- },
-
- _generateUV : function(progressX, progressY, uvs, offset) {
- var out = this.outUvs;
- var px1 = uvs[0] + (uvs[2] - uvs[0]) * progressX;
- var px2 = uvs[4] + (uvs[6] - uvs[4]) * progressX;
- var py1 = uvs[1] + (uvs[3] - uvs[1]) * progressX;
- var py2 = uvs[5] + (uvs[7] - uvs[5]) * progressX;
- out[offset] = px1 + (px2 - px1) * progressY;
- out[offset+1] = py1 + (py2 - py1) * progressY;
- },
-
- _isAngleIn : function(angle, start, rangeAngle) {
- var pi_2 = Math.PI * 2;
- while(angle < start || angle >= start + pi_2) {
- if(angle < start) {
- angle += pi_2;
- }
- if(angle >= start + pi_2) {
- angle -= pi_2;
- }
- }
-
- return angle <= start + rangeAngle;
- },
-
- //[0,PI * 2)
- _getVertAngle: function(start, end) {
- var placementX, placementY;
- placementX = end.x - start.x;
- placementY = end.y - start.y;
-
- if(placementX === 0 && placementY === 0) {
- return undefined;
- } else if(placementX === 0) {
- if(placementY > 0) {
- return Math.PI * 0.5;
- } else {
- return Math.PI * 1.5;
- }
- } else {
- var angle = Math.atan(placementY / placementX);
- if(placementX < 0) {
- angle += Math.PI;
- }
-
- return angle;
- }
- },
-
- _getInsectedPoints: function(left, right, bottom, top, center, angle, intersectPoints) {
- //left bottom, right, top
- var result = [null, null, null, null];
- var sinAngle = Math.sin(angle);
- var cosAngle = Math.cos(angle);
- var tanAngle,cotAngle;
- if(Math.cos(angle) !== 0) {
- tanAngle = sinAngle / cosAngle;
- //calculate right and left
- if((left - center.x) * cosAngle > 0) {
- var yleft = center.y + tanAngle * (left - center.x);
- intersectPoints[0].x = left;
- intersectPoints[0].y = yleft;
- }
- if((right - center.x) * cosAngle > 0) {
- var yright = center.y + tanAngle * (right - center.x);
-
- intersectPoints[2].x = right;
- intersectPoints[2].y = yright;
- }
-
- }
-
- if(Math.sin(angle) !== 0) {
- cotAngle = cosAngle / sinAngle;
- //calculate top and bottom
- if((top - center.y) * sinAngle > 0) {
- var xtop = center.x + cotAngle * (top-center.y);
- intersectPoints[3].x = xtop;
- intersectPoints[3].y = top;
- }
- if((bottom - center.y) * sinAngle > 0) {
- var xbottom = center.x + cotAngle * (bottom-center.y);
- intersectPoints[1].x = xbottom;
- intersectPoints[1].y = bottom;
- }
-
- }
- return result;
- },
-
- _calculateVertices : function (wt, spriteFrame, contentSize) {
- var x0, x3, y0, y3;
- x0 = 0;
- y0 = 0;
- x3 = contentSize.width;
- y3 = contentSize.height;
-
- this._vertices[0].x = x0;
- this._vertices[0].y = y0;
- this._vertices[1].x = x3;
- this._vertices[1].y = y3;
- },
-
- _calculateUVs : function (spriteFrame) {
- var atlasWidth = spriteFrame._texture.width;
- var atlasHeight = spriteFrame._texture.height;
- var textureRect = spriteFrame._rect;
-
- //uv computation should take spritesheet into account.
- var u0, u3, v0, v3;
- var texelCorrect = macro.FIX_ARTIFACTS_BY_STRECHING_TEXEL ? 0.5 : 0;
-
- if (spriteFrame._rotated) {
- u0 = (textureRect.x + texelCorrect) / atlasWidth;
- u3 = (textureRect.x + textureRect.height - texelCorrect) / atlasWidth;
-
- v0 = (textureRect.y + texelCorrect) / atlasHeight;
- v3 = (textureRect.y + textureRect.width - texelCorrect) / atlasHeight;
- }
- else {
- u0 = (textureRect.x + texelCorrect) / atlasWidth;
- u3 = (textureRect.x + textureRect.width - texelCorrect) / atlasWidth;
-
- v0 = (textureRect.y + texelCorrect) / atlasHeight;
- v3 = (textureRect.y + textureRect.height - texelCorrect) / atlasHeight;
- }
-
- this._uvs[0].x = u0;
- this._uvs[0].y = v3;
- this._uvs[1].x = u3;
- this._uvs[1].y = v0;
- }
-};
-
-var meshQuadGenerator = {
- _rebuildQuads_base: function (sprite, spriteFrame, polygonInfo) {
- if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
- return;
- }
-
- var spriteFrame = sprite._spriteFrame,
- polygonInfo = sprite._meshPolygonInfo
-
- if (!polygonInfo) {
- return;
- }
-
- var wt = sprite._renderCmd._worldTransform;
- var srcVerts = polygonInfo.triangles.verts;
- var vertices = sprite._vertices;
- var uvs = sprite._uvs;
- var count = srcVerts.length;
- var corner = sprite._corner;
-
- var dataLength = count * 2;
- if (vertices.length < dataLength) {
- dataPool.put(vertices);
- vertices = dataPool.get(dataLength) || new Float32Array(dataLength);
- sprite._vertices = vertices;
- }
- if (uvs.length < dataLength) {
- dataPool.put(uvs);
- uvs = dataPool.get(dataLength) || new Float32Array(dataLength);
- sprite._uvs = uvs;
- }
-
- var l = Infinity, b = Infinity,
- r = -Infinity, t = -Infinity;
- for (var i = 0; i < count; i++) {
- var x = srcVerts[i].x * wt.a + srcVerts[i].y * wt.c + wt.tx;
- var y = srcVerts[i].x * wt.b + srcVerts[i].y * wt.d + wt.ty;
- vertices[i * 2] = x;
- vertices[i * 2 + 1] = y;
- uvs[i * 2] = srcVerts[i].u;
- uvs[i * 2 + 1] = srcVerts[i].v;
-
- if (x < l) {
- l = x;
- corner[0] = i * 2; // left
- }
-
- if (x > r) {
- r = x;
- corner[1] = i * 2; // right
- }
-
- if (y < b) {
- b = y;
- corner[2] = i * 2; // bottom
- }
-
- if (y > t) {
- t = y;
- corner[3] = i * 2; // top
- }
- }
-
- sprite._vertCount = count;
- }
-};
-
-cc.Scale9Sprite = _ccsg.Node.extend({
- //resource data, could be async loaded.
- _spriteFrame: null,
-
- //scale 9 data
- _insetLeft: 0,
- _insetRight: 0,
- _insetTop: 0,
- _insetBottom: 0,
- //blend function
- _blendFunc: null,
- //sliced or simple
- _renderingType: 1,
- //bright or not
- _brightState: 0,
- //rendering quads shared by canvas and webgl
- _rawVerts: null,
- _rawUvs: null,
- _vertices: null,
- _uvs: null,
- _vertCount: 0,
- _quadsDirty: true,
- _uvsDirty: true,
- _isTriangle: false,
- _isTrimmedContentSize: true,
- //fill type
- _fillType: 0,
- //for fill radial
- _fillCenter: null,
- //normalized filled start and range
- _fillStart: 0,
- _fillRange: Math.PI * 2,
- _distortionOffset: null,
- _distortionTiling: null,
- _meshPolygonInfo: null,
-
- ctor: function (textureOrSpriteFrame) {
- _ccsg.Node.prototype.ctor.call(this);
- this._renderCmd.setState(this._brightState);
- this._blendFunc = cc.BlendFunc._alphaNonPremultiplied();
- this._fillCenter = cc.v2(0,0);
- this.setAnchorPoint(cc.p(0.5, 0.5));
- // Init vertex data for simple
- this._rawVerts = null;
- this._rawUvs = null;
- this._vertices = dataPool.get(8) || new Float32Array(8);
- this._uvs = dataPool.get(8) || new Float32Array(8);
- // Init sprite frame
- if (typeof textureOrSpriteFrame === 'string' || textureOrSpriteFrame instanceof cc.Texture2D) {
- this.initWithTexture(textureOrSpriteFrame);
- }
- else if (textureOrSpriteFrame instanceof cc.SpriteFrame) {
- this.initWithSpriteFrame(textureOrSpriteFrame);
- }
-
- if (webgl === undefined) {
- webgl = cc._renderType === cc.game.RENDER_TYPE_WEBGL;
- }
-
- this._corner = [];
- },
-
- loaded: function () {
- if (this._spriteFrame === null) {
- return false;
- } else {
- return this._spriteFrame.textureLoaded();
- }
- },
-
- /**
- * Initializes a 9-slice sprite with a texture file
- *
- * @param textureOrTextureFile The name of the texture file.
- */
- initWithTexture: function (textureOrTextureFile) {
- this.setTexture(textureOrTextureFile);
- },
-
- /**
- * Initializes a 9-slice sprite with an sprite frame
- * @param spriteFrameOrSFName The sprite frame object.
- */
- initWithSpriteFrame: function (spriteFrameOrSFName) {
- this.setSpriteFrame(spriteFrameOrSFName);
- },
-
- /**
- * Change the texture file of 9 slice sprite
- *
- * @param textureOrTextureFile The name of the texture file.
- */
- setTexture: function (textureOrTextureFile) {
- var spriteFrame = new cc.SpriteFrame(textureOrTextureFile);
- this.setSpriteFrame(spriteFrame);
- },
-
- /**
- * Change the sprite frame of 9 slice sprite
- *
- * @param spriteFrame The SpriteFrame object.
- */
- setSpriteFrame: function (spriteFrame) {
- if (spriteFrame) {
- this._spriteFrame = spriteFrame;
- this._quadsDirty = true;
- this._uvsDirty = true;
- this._renderCmd._needDraw = false;
- var self = this;
- var onResourceDataLoaded = function () {
- if (cc.sizeEqualToSize(self._contentSize, cc.size(0, 0))) {
- self.setContentSize(self._spriteFrame._rect);
- }
- self._renderCmd._needDraw = true;
- self._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.contentDirty);
- };
- if (spriteFrame.textureLoaded()) {
- onResourceDataLoaded();
- } else {
- spriteFrame.once('load', onResourceDataLoaded, this);
- }
- }
- },
-
- /**
- * Sets the source blending function.
- *
- * @param blendFunc A structure with source and destination factor to specify pixel arithmetic. e.g. {GL_ONE, GL_ONE}, {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}.
- */
- setBlendFunc: function (blendFunc, dst) {
- if (dst === undefined) {
- this._blendFunc.src = blendFunc.src || cc.macro.BLEND_SRC;
- this._blendFunc.dst = blendFunc.dst || cc.macro.BLEND_DST;
- }
- else {
- this._blendFunc.src = blendFunc || cc.macro.BLEND_SRC;
- this._blendFunc.dst = dst || cc.macro.BLEND_DST;
- }
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.contentDirty);
- },
-
- /**
- * Returns the blending function that is currently being used.
- *
- * @return A BlendFunc structure with source and destination factor which specified pixel arithmetic.
- */
- getBlendFunc: function () {
- return new cc.BlendFunc(this._blendFunc.src, this._blendFunc.dst);
- },
-
- // overrides
- setContentSize: function (width, height) {
- if (height === undefined) {
- height = width.height;
- width = width.width;
- }
- if (width === this._contentSize.width && height === this._contentSize.height) {
- return;
- }
-
- _ccsg.Node.prototype.setContentSize.call(this, width, height);
- this._quadsDirty = true;
- },
-
- //
- enableTrimmedContentSize: function (isTrimmed) {
- if (this._isTrimmedContentSize !== isTrimmed) {
- this._isTrimmedContentSize = isTrimmed;
- this._quadsDirty = true;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.contentDirty);
- }
- },
-
- isTrimmedContentSizeEnabled: function () {
- return this._isTrimmedContentSize;
- },
- /**
- * Change the state of 9-slice sprite.
- * @see `State`
- * @param state A enum value in State.
- */
- setState: function (state) {
- this._brightState = state;
- this._renderCmd.setState(state);
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.contentDirty);
- },
-
- /**
- * Query the current bright state.
- * @return @see `State`
- */
- getState: function () {
- return this._brightState;
- },
-
- /**
- * change the rendering type, could be simple or slice
- * @return @see `RenderingType`
- */
- setRenderingType: function (type) {
- if (this._renderingType === type) return;
- this._renderingType = type;
- this._quadsDirty = true;
- this._uvsDirty = true;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.contentDirty);
- },
- /**
- * get the rendering type, could be simple or slice
- * @return @see `RenderingType`
- */
- getRenderingType: function () {
- return this._renderingType;
- },
- /**
- * change the left border of 9 slice sprite, it should be specified before trimmed.
- * @param insetLeft left border.
- */
- setInsetLeft: function (insetLeft) {
- this._insetLeft = insetLeft;
- this._quadsDirty = true;
- this._uvsDirty = true;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.contentDirty);
- },
- /**
- * get the left border of 9 slice sprite, the result is specified before trimmed.
- * @return left border.
- */
- getInsetLeft: function () {
- return this._insetLeft;
- },
- /**
- * change the top border of 9 slice sprite, it should be specified before trimmed.
- * @param insetTop top border.
- */
- setInsetTop: function (insetTop) {
- this._insetTop = insetTop;
- this._quadsDirty = true;
- this._uvsDirty = true;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.contentDirty);
- },
-
- /**
- * get the top border of 9 slice sprite, the result is specified before trimmed.
- * @return top border.
- */
- getInsetTop: function () {
- return this._insetTop;
- },
-
- /**
- * change the right border of 9 slice sprite, it should be specified before trimmed.
- * @param insetRight right border.
- */
- setInsetRight: function (insetRight) {
- this._insetRight = insetRight;
- this._quadsDirty = true;
- this._uvsDirty = true;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.contentDirty);
- },
-
- /**
- * get the right border of 9 slice sprite, the result is specified before trimmed.
- * @return right border.
- */
- getInsetRight: function () {
- return this._insetRight;
- },
-
- /**
- * change the bottom border of 9 slice sprite, it should be specified before trimmed.
- * @param insetBottom bottom border.
- */
- setInsetBottom: function (insetBottom) {
- this._insetBottom = insetBottom;
- this._quadsDirty = true;
- this._uvsDirty = true;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.contentDirty);
- },
- /**
- * get the bottom border of 9 slice sprite, the result is specified before trimmed.
- * @return bottom border.
- */
- getInsetBottom: function () {
- return this._insetBottom;
- },
-
- setFillType: function(value) {
- if(this._fillType === value)
- return;
- this._fillType = value;
- if(this._renderingType === RenderingType.FILLED) {
- this._quadsDirty = true;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.contentDirty);
- }
- },
-
- getFillType: function() {
- return this._fillType;
- },
-
- setFillCenter: function(value, y) {
- this._fillCenter = cc.v2(value,y);
- if(this._renderingType === RenderingType.FILLED && this._fillType === FillType.RADIAL) {
- this._quadsDirty = true;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.contentDirty);
- }
- },
-
- setDistortionTiling: function(valueOrX, y) {
- if(y === undefined) {
- y = valueOrX.y;
- valueOrX = valueOrX.x;
- }
- this._distortionTiling = this._distortionTiling || cc.v2(0,0);
- this._distortionTiling.x = valueOrX;
- this._distortionTiling.y = y;
- },
-
- setDistortionOffset: function(valueOrX, y) {
- if(y === undefined) {
- y = valueOrX.y;
- valueOrX = valueOrX.x;
- }
- this._distortionOffset = this._distortionOffset || cc.v2(0,0);
- this._distortionOffset.x = valueOrX;
- this._distortionOffset.y = y;
- },
-
- getFillCenter: function() {
- return cc.v2(this._fillCenter);
- },
-
- setFillStart: function(value) {
- if(this._fillStart === value)
- return;
- this._fillStart = value;
- if(this._renderingType === RenderingType.FILLED) {
- this._quadsDirty = true;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.contentDirty);
- }
- },
-
- getFillStart: function() {
- return this._fillStart;
- },
-
- setFillRange: function(value) {
- if(this._fillRange === value)
- return;
- this._fillRange = value;
- if(this._renderingType === RenderingType.FILLED ) {
- this._quadsDirty = true;
- this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.contentDirty);
- }
- },
-
- getFillRange: function() {
- return this._fillRange;
- },
-
- _rebuildQuads: function () {
- if (!this._spriteFrame || !this._spriteFrame._textureLoaded) {
- this._renderCmd._needDraw = false;
- return;
- }
- this._isTriangle = false;
-
- var quadGenerator;
- switch (this._renderingType) {
- case RenderingType.SIMPLE:
- quadGenerator = simpleQuadGenerator;
- break;
- case RenderingType.SLICED:
- quadGenerator = scale9QuadGenerator;
- break;
- case RenderingType.TILED:
- quadGenerator = tiledQuadGenerator;
- break;
- case RenderingType.FILLED:
- if (this._fillType === FillType.RADIAL) {
- quadGenerator = fillQuadGeneratorRadial;
- }
- else {
- quadGenerator = fillQuadGeneratorBar;
- }
- break;
- case RenderingType.MESH:
- quadGenerator = meshQuadGenerator;
- break;
- }
-
- if (quadGenerator) {
- quadGenerator._rebuildQuads_base(this);
- }
- else {
- this._quadsDirty = false;
- this._uvsDirty = false;
- this._renderCmd._needDraw = false;
- cc.errorID(2627);
- }
-
- this._quadsDirty = false;
- this._uvsDirty = false;
- },
- _createRenderCmd: function () {
- if (cc._renderType === cc.game.RENDER_TYPE_CANVAS)
- return new cc.Scale9Sprite.CanvasRenderCmd(this);
- else
- return new cc.Scale9Sprite.WebGLRenderCmd(this);
- },
-
- setMeshPolygonInfo: function (polygonInfo) {
- /**
- * polygonInfo in format:
- * {
- * triangles: {
- * verts: displayVertices,
- * indices: vertexIndices
- * },
- * rect: boundsRect
- * }
- */
- this.setRenderingType(RenderingType.MESH);
- this._meshPolygonInfo = polygonInfo;
- this._quadsDirty = true;
- this._uvsDirty = true;
- },
-
- getMeshPolygonInfo: function () {
- return this._meshPolygonInfo;
- }
-});
-
-var _p = cc.Scale9Sprite.prototype;
-cc.js.addon(_p, EventTarget.prototype);
-// Extended properties
-cc.defineGetterSetter(_p, 'insetLeft', _p.getInsetLeft, _p.setInsetLeft);
-cc.defineGetterSetter(_p, 'insetTop', _p.getInsetTop, _p.setInsetTop);
-cc.defineGetterSetter(_p, 'insetRight', _p.getInsetRight, _p.setInsetRight);
-cc.defineGetterSetter(_p, 'insetBottom', _p.getInsetBottom, _p.setInsetBottom);
-
-cc.Scale9Sprite.state = {NORMAL: 0, GRAY: 1, DISTORTION: 2};
-
-/**
- * Enum for sprite type
- * @enum SpriteType
- */
-var RenderingType = cc.Scale9Sprite.RenderingType = cc.Enum({
- /**
- * @property {Number} SIMPLE
- */
- SIMPLE: 0,
- /**
- * @property {Number} SLICED
- */
- SLICED: 1,
- /*
- * @property {Number} TILED
- */
- TILED: 2,
- /*
- * @property {Number} FILLED
- */
- FILLED: 3,
- /*
- * @property {Number} MESH
- */
- MESH: 4
-});
-
-var FillType = cc.Scale9Sprite.FillType = cc.Enum({
- HORIZONTAL: 0,
- VERTICAL: 1,
- RADIAL:2,
-});
diff --git a/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js b/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js
deleted file mode 100644
index 485e8818951..00000000000
--- a/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js
+++ /dev/null
@@ -1,202 +0,0 @@
-/****************************************************************************
- Copyright (c) 2016 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.
- ****************************************************************************/
-
-cc.Scale9Sprite.CanvasRenderCmd = function (renderable) {
- this._rootCtor(renderable);
- if (this._node.loaded()) {
- this._needDraw = true;
- }
- else {
- this._needDraw = false;
- }
- this._state = cc.Scale9Sprite.state.NORMAL;
- this._originalTexture = this._textureToRender = null;
-};
-
-var proto = cc.Scale9Sprite.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
-proto.constructor = cc.Scale9Sprite.CanvasRenderCmd;
-
-proto.updateTransform = function (parentCmd) {
- this.originUpdateTransform(parentCmd);
- this._node._rebuildQuads();
-};
-
-proto._doCulling = function () {
- var rect = cc.visibleRect,
- bb = this._currentRegion,
- l = bb._minX, r = bb._maxX, b = bb._minY, t = bb._maxY,
- vl = rect.left.x, vr = rect.right.x, vt = rect.top.y, vb = rect.bottom.y;
-
- this._needDraw = !(r < vl || l > vr || t < vb || b > vt);
-};
-
-proto._updateDisplayColor = function(parentColor){
- _ccsg.Node.WebGLRenderCmd.prototype._updateDisplayColor.call(this, parentColor);
- this._originalTexture = this._textureToRender = null;
-};
-
-proto._syncDisplayColor = function(parentColor){
- _ccsg.Node.WebGLRenderCmd.prototype._syncDisplayColor.call(this, parentColor);
- this._originalTexture = this._textureToRender = null;
-};
-
-proto.setState = function(state){
- if(this._state === state) return;
-
- this._state = state;
- this._originalTexture = this._textureToRender = null;
-};
-
-proto.rendering = function (ctx, scaleX, scaleY) {
- var node = this._node;
- var locDisplayOpacity = this._displayedOpacity;
- var alpha = locDisplayOpacity/ 255;
- var locTexture = null;
- if (node._spriteFrame) locTexture = node._spriteFrame._texture;
- if (!node.loaded() || locDisplayOpacity === 0)
- return;
- if (this._textureToRender === null || this._originalTexture !== locTexture) {
- this._textureToRender = this._originalTexture = locTexture;
- if (cc.Scale9Sprite.state.GRAY === this._state) {
- this._textureToRender = this._textureToRender._generateGrayTexture();
- }
- var color = node.getDisplayedColor();
- if (locTexture && (color.r !== 255 || color.g !==255 || color.b !== 255))
- this._textureToRender = this._textureToRender._generateColorTexture(color.r,color.g,color.b);
- }
-
- var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
- wrapper.setTransform(this._worldTransform, scaleX, scaleY);
- wrapper.setCompositeOperation(_ccsg.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc(node._blendFunc));
- wrapper.setGlobalAlpha(alpha);
-
- if (this._textureToRender) {
- if (node._quadsDirty) {
- node._rebuildQuads();
- }
- var sx,sy,sw,sh;
- var x, y, w,h;
- var textureWidth = this._textureToRender.width;
- var textureHeight = this._textureToRender.height;
- var image = this._textureToRender._image;
- var vertices = node._vertices;
- var uvs = node._uvs;
- var i = 0, off = 0;
-
- if (node._isTriangle) {
- var rawVerts = node._rawVerts, rawUvs = node._rawUvs;
- x = rawVerts[0];
- y = rawVerts[1];
- w = rawVerts[6] - x;
- h = rawVerts[7] - y;
- y = - y - h;
-
- sx = rawUvs[4] * textureWidth;
- sy = rawUvs[5] * textureHeight;
- sw = (rawUvs[6] - rawUvs[0]) * textureWidth;
- sh = (rawUvs[1] - rawUvs[7]) * textureHeight;
-
-
- wrapper.save();
- context.beginPath();
- var triangleCount = Math.floor(node._vertCount / 3);
-
- for (i = 0, off = 0; i < triangleCount; i++) {
- context.moveTo(vertices[off++], -vertices[off++]);
- context.lineTo(vertices[off++], -vertices[off++]);
- context.lineTo(vertices[off++], -vertices[off++]);
- }
-
- context.clip();
- if (this._textureToRender._pattern !== '') {
- wrapper.setFillStyle(context.createPattern(image, this._textureToRender._pattern));
- context.fillRect(x, y, w, h);
- }
- else {
- if (sw > 0 && sh > 0 && w > 0 && h > 0) {
- context.drawImage(image,
- sx, sy, sw, sh,
- x, y, w, h);
- }
- }
-
- wrapper.restore();
- cc.g_NumberOfDraws += triangleCount;
- }
- else if (node._renderingType === cc.Scale9Sprite.RenderingType.SLICED) {
- // Sliced use a special vertices layout 16 vertices for 9 quads
- for (var r = 0; r < 3; ++r) {
- for (var c = 0; c < 3; ++c) {
- off = r*8 + c*2;
- x = vertices[off];
- y = vertices[off+1];
- w = vertices[off+10] - x;
- h = vertices[off+11] - y;
- y = - y - h;
-
- sx = uvs[off] * textureWidth;
- sy = uvs[off+11] * textureHeight;
- sw = (uvs[off+10] - uvs[off]) * textureWidth;
- sh = (uvs[off+1] - uvs[off+11]) * textureHeight;
-
- if (sw > 0 && sh > 0 && w > 0 && h > 0) {
- context.drawImage(image,
- sx, sy, sw, sh,
- x, y, w, h);
- }
- }
- }
- cc.g_NumberOfDraws += 9;
- }
- else {
- var quadCount = Math.floor(node._vertCount / 4);
- for (i = 0, off = 0; i < quadCount; i++) {
- x = vertices[off];
- y = vertices[off+1];
- w = vertices[off+6] - x;
- h = vertices[off+7] - y;
- y = - y - h;
-
- sx = uvs[off] * textureWidth;
- sy = uvs[off+7] * textureHeight;
- sw = (uvs[off+6] - uvs[off]) * textureWidth;
- sh = (uvs[off+1] - uvs[off+7]) * textureHeight;
-
-
- if (this._textureToRender._pattern !== '') {
- wrapper.setFillStyle(context.createPattern(image, this._textureToRender._pattern));
- context.fillRect(x, y, w, h);
- } else {
- if (sw > 0 && sh > 0 && w > 0 && h > 0) {
- context.drawImage(image,
- sx, sy, sw, sh,
- x, y, w, h);
- }
- }
- off += 8;
- }
- cc.g_NumberOfDraws += quadCount;
- }
- }
-};
diff --git a/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js b/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js
deleted file mode 100644
index b31d417330f..00000000000
--- a/cocos2d/core/sprites/CCScale9SpriteWebGLRenderCmd.js
+++ /dev/null
@@ -1,308 +0,0 @@
-/****************************************************************************
- Copyright (c) 2016 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.
- ****************************************************************************/
-
-var ccgl = cc.gl;
-
-cc.Scale9Sprite.WebGLRenderCmd = function (renderable) {
- this._rootCtor(renderable);
- if (this._node.loaded()) {
- this._needDraw = true;
- }
- else {
- this._needDraw = false;
- }
-
- this.vertexType = cc.renderer.VertexType.QUAD;
- this._dirty = false;
- this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_SPRITE_POSITION_TEXTURECOLOR);
-};
-
-var Scale9Sprite = cc.Scale9Sprite;
-var proto = Scale9Sprite.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
-proto.constructor = Scale9Sprite.WebGLRenderCmd;
-
-proto._uploadSliced = function (vertices, uvs, color, z, f32buffer, ui32buffer, offset) {
- var off;
- for (var r = 0; r < 3; ++r) {
- for (var c = 0; c < 3; ++c) {
- off = r*8 + c*2;
- // lb
- f32buffer[offset] = vertices[off];
- f32buffer[offset+1] = vertices[off+1];
- f32buffer[offset+2] = z;
- ui32buffer[offset+3] = color;
- f32buffer[offset+4] = uvs[off];
- f32buffer[offset+5] = uvs[off+1];
- offset += 6;
- // rb
- f32buffer[offset] = vertices[off+2];
- f32buffer[offset + 1] = vertices[off+3];
- f32buffer[offset + 2] = z;
- ui32buffer[offset + 3] = color;
- f32buffer[offset + 4] = uvs[off+2];
- f32buffer[offset + 5] = uvs[off+3];
- offset += 6;
- // lt
- f32buffer[offset] = vertices[off+8];
- f32buffer[offset + 1] = vertices[off+9];
- f32buffer[offset + 2] = z;
- ui32buffer[offset + 3] = color;
- f32buffer[offset + 4] = uvs[off+8];
- f32buffer[offset + 5] = uvs[off+9];
- offset += 6;
- // rt
- f32buffer[offset] = vertices[off+10];
- f32buffer[offset + 1] = vertices[off+11];
- f32buffer[offset + 2] = z;
- ui32buffer[offset + 3] = color;
- f32buffer[offset + 4] = uvs[off+10];
- f32buffer[offset + 5] = uvs[off+11];
- offset += 6;
- }
- }
- return 36;
-};
-
-proto.updateTransform = function (parentCmd) {
- this.originUpdateTransform(parentCmd);
- this._node._rebuildQuads();
-};
-
-proto._doCulling = function () {
- var node = this._node;
- var rect = cc.visibleRect;
-
- if (this._cameraFlag > 0) {
- rect = cc.Camera.main.visibleRect;
- }
-
- var vl = rect.left.x;
- var vr = rect.right.x;
- var vt = rect.top.y;
- var vb = rect.bottom.y;
-
- // x1, y1 leftBottom
- // x2, y2 rightBottom
- // x3, y3 leftTop
- // x4, y4 rightTop
- var vert = node._vertices,
- corner = node._corner,
- c0 = corner[0], c1 = corner[1], c2 = corner[2], c3 = corner[3],
- x0 = vert[c0], x1 = vert[c1], x2 = vert[c2], x3 = vert[c3],
- y0 = vert[c0 + 1], y1 = vert[c1 + 1], y2 = vert[c2 + 1], y3 = vert[c3 + 1];
- if (((x0-vl) & (x1-vl) & (x2-vl) & (x3-vl)) >> 31 || // All outside left
- ((vr-x0) & (vr-x1) & (vr-x2) & (vr-x3)) >> 31 || // All outside right
- ((y0-vb) & (y1-vb) & (y2-vb) & (y3-vb)) >> 31 || // All outside bottom
- ((vt-y0) & (vt-y1) & (vt-y2) & (vt-y3)) >> 31) // All outside top
- {
- this._needDraw = false;
- }
- else {
- this._needDraw = true;
- }
-};
-
-proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset){
- var node = this._node;
- if (this._displayedOpacity === 0) {
- return 0;
- }
-
- // Rebuild vertex data
- if (node._quadsDirty) {
- node._rebuildQuads();
- }
-
- if (node._distortionOffset && this._shaderProgram === Scale9Sprite.WebGLRenderCmd._distortionProgram) {
- this._shaderProgram.use();
- this._shaderProgram.setUniformLocationWith2f(
- Scale9Sprite.WebGLRenderCmd._distortionOffset,
- node._distortionOffset.x, node._distortionOffset.y
- );
- this._shaderProgram.setUniformLocationWith2f(
- Scale9Sprite.WebGLRenderCmd._distortionTiling,
- node._distortionTiling.x, node._distortionTiling.y
- );
- cc.renderer._breakBatch();
- }
-
- // Color & z
- var opacity = this._displayedOpacity;
- var color, colorVal = this._displayedColor._val;
- if (node._opacityModifyRGB) {
- var a = opacity / 255,
- r = this._displayedColor.r * a,
- g = this._displayedColor.g * a,
- b = this._displayedColor.b * a;
- color = ((opacity<<24) >>> 0) + (b<<16) + (g<<8) + r;
- }
- else {
- color = ((opacity<<24) >>> 0) + ((colorVal&0xff00)<<8) + ((colorVal&0xff0000)>>8) + (colorVal>>>24);
- }
- var z = node._vertexZ;
-
- // Upload data
- var vertices = node._vertices;
- var uvs = node._uvs;
- var types = Scale9Sprite.RenderingType;
- var offset = vertexDataOffset;
- var len = 0;
- switch (node._renderingType) {
- case types.SIMPLE:
- case types.TILED:
- case types.FILLED:
- case types.MESH:
- // Inline for performance
- len = this._node._vertCount;
- for (var i = 0, srcOff = 0; i < len; i++, srcOff += 2) {
- f32buffer[offset] = vertices[srcOff];
- f32buffer[offset + 1] = vertices[srcOff+1];
- f32buffer[offset + 2] = z;
- ui32buffer[offset + 3] = color;
- f32buffer[offset + 4] = uvs[srcOff];
- f32buffer[offset + 5] = uvs[srcOff+1];
- offset += 6;
- }
- break;
- case types.SLICED:
- len = this._uploadSliced(vertices, uvs, color, z, f32buffer, ui32buffer, offset);
- break;
- }
-
- if (node._renderingType === types.MESH ) {
- this.vertexType = cc.renderer.VertexType.CUSTOM;
- }
- else if (node._renderingType === types.FILLED && node._fillType === Scale9Sprite.FillType.RADIAL) {
- this.vertexType = cc.renderer.VertexType.TRIANGLE;
- }
- else {
- this.vertexType = cc.renderer.VertexType.QUAD;
- }
- return len;
-};
-
-proto.uploadIndexData = function (indexData, indexSize, batchingSize) {
- var polygonInfo = this._node._meshPolygonInfo;
- if (! polygonInfo) {
- return 0;
- }
-
- var indices = polygonInfo.triangles.indices;
- var len = indices.length;
- for (var i = 0; i < len; i++) {
- indexData[indexSize + i] = batchingSize + indices[i];
- }
-
- return len;
-};
-
-proto.setState = function (state) {
- if (state === Scale9Sprite.state.NORMAL) {
- this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_SPRITE_POSITION_TEXTURECOLOR);
- } else if (state === Scale9Sprite.state.GRAY) {
- this._shaderProgram = cc.Scale9Sprite.WebGLRenderCmd._getGrayShaderProgram();
- } else if (state === Scale9Sprite.state.DISTORTION) {
- this._shaderProgram = cc.Scale9Sprite.WebGLRenderCmd._getDistortionProgram();
- }
-};
-
-Scale9Sprite.WebGLRenderCmd._grayShaderProgram = null;
-Scale9Sprite.WebGLRenderCmd._getGrayShaderProgram = function(){
- var grayShader = Scale9Sprite.WebGLRenderCmd._grayShaderProgram;
- if (grayShader)
- return grayShader;
-
- grayShader = new cc.GLProgram();
- grayShader.initWithVertexShaderByteArray(cc.PresetShaders.SPRITE_POSITION_TEXTURE_COLOR_VERT, cc.Scale9Sprite.WebGLRenderCmd._grayShaderFragment);
- grayShader.addAttribute(cc.macro.ATTRIBUTE_NAME_POSITION, cc.macro.VERTEX_ATTRIB_POSITION);
- grayShader.addAttribute(cc.macro.ATTRIBUTE_NAME_COLOR, cc.macro.VERTEX_ATTRIB_COLOR);
- grayShader.addAttribute(cc.macro.ATTRIBUTE_NAME_TEX_COORD, cc.macro.VERTEX_ATTRIB_TEX_COORDS);
- grayShader.link();
- grayShader.updateUniforms();
-
- Scale9Sprite.WebGLRenderCmd._grayShaderProgram = grayShader;
- return grayShader;
-};
-
-Scale9Sprite.WebGLRenderCmd._grayShaderFragment =
- "precision lowp float;\n"
- + "varying vec4 v_fragmentColor;\n"
- + "varying vec2 v_texCoord;\n"
- + "void main()\n"
- + "{\n"
- + "vec4 c = v_fragmentColor * texture2D(CC_Texture0, v_texCoord);\n"
- + "float gray = 0.2126*c.r + 0.7152*c.g + 0.0722*c.b;\n"
- + "gl_FragColor = vec4(gray, gray, gray, c.a);\n"
- + "}";
-
-Scale9Sprite.WebGLRenderCmd._distortionProgram = null;
-Scale9Sprite.WebGLRenderCmd._getDistortionProgram = function(){
- var shader = Scale9Sprite.WebGLRenderCmd._distortionProgram;
- if(shader)
- return shader;
-
- shader = new cc.GLProgram();
- shader.initWithVertexShaderByteArray(cc.PresetShaders.SPRITE_POSITION_TEXTURE_COLOR_VERT, distortionSpriteShader.fShader);
- shader.addAttribute(cc.macro.ATTRIBUTE_NAME_POSITION, cc.macro.VERTEX_ATTRIB_POSITION);
- shader.addAttribute(cc.macro.ATTRIBUTE_NAME_COLOR, cc.macro.VERTEX_ATTRIB_COLOR);
- shader.addAttribute(cc.macro.ATTRIBUTE_NAME_TEX_COORD, cc.macro.VERTEX_ATTRIB_TEX_COORDS);
- shader.link();
- shader.updateUniforms();
-
- Scale9Sprite.WebGLRenderCmd._distortionProgram = shader;
- Scale9Sprite.WebGLRenderCmd._distortionOffset = shader.getUniformLocationForName('u_offset');
- Scale9Sprite.WebGLRenderCmd._distortionTiling = shader.getUniformLocationForName('u_offset_tiling');
- return shader;
-};
-
-var distortionSpriteShader = {
- shaderKey: 'cc.Sprite.Shader.Distortion',
- fShader: "precision lowp float;\n"
- + "varying vec4 v_fragmentColor;\n"
- + "varying vec2 v_texCoord;\n"
- + "uniform vec2 u_offset;\n"
- + "uniform vec2 u_offset_tiling;\n"
- + "const float PI = 3.14159265359;\n"
- + "void main()\n"
- + "{\n"
- + "float halfPI = 0.5 * PI;\n"
- + "float maxFactor = sin(halfPI);\n"
- + "vec2 uv = v_texCoord;\n"
- + "vec2 xy = 2.0 * uv.xy - 1.0;\n"
- + "float d = length(xy);\n"
- + "if (d < (2.0-maxFactor)) {\n"
- + "d = length(xy * maxFactor);\n"
- + "float z = sqrt(1.0 - d * d);\n"
- + "float r = atan(d, z) / PI;\n"
- + "float phi = atan(xy.y, xy.x);\n"
- + "uv.x = r * cos(phi) + 0.5;\n"
- + "uv.y = r * sin(phi) + 0.5;\n"
- + "} else {\n"
- + "discard;\n"
- + "}\n"
- + "uv = uv * u_offset_tiling + u_offset;\n"
- + "uv = fract(uv);\n"
- + "gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, uv);\n"
- + "}"
-};
diff --git a/cocos2d/core/sprites/CCSpriteBatchNode.js b/cocos2d/core/sprites/CCSpriteBatchNode.js
deleted file mode 100644
index ddba1cb47f3..00000000000
--- a/cocos2d/core/sprites/CCSpriteBatchNode.js
+++ /dev/null
@@ -1,253 +0,0 @@
-
-/****************************************************************************
- Copyright (c) 2008-2010 Ricardo Quesada
- 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.
- ****************************************************************************/
-
-
-/**
- *
- * A cc.SpriteBatchNode can reference one and only one texture (one image file, one texture atlas).
- * Only the cc.Sprites that are contained in that texture can be added to the cc.SpriteBatchNode.
- * All cc.Sprites added to a cc.SpriteBatchNode are drawn in one WebGL draw call.
- * If the cc.Sprites are not added to a cc.SpriteBatchNode then an WebGL draw call will be needed for each one, which is less efficient.
- *
- * Limitations:
- * - The only object that is accepted as child (or grandchild, grand-grandchild, etc...) is _ccsg.Sprite or any subclass of _ccsg.Sprite.
- * eg: particles, labels and layer can't be added to a cc.SpriteBatchNode.
- * - Either all its children are Aliased or Antialiased. It can't be a mix.
- * This is because "alias" is a property of the texture, and all the sprites share the same texture.
- *
- * @class
- * @extends _ccsg.Node
- *
- * @param {String|cc.Texture2D} fileImage
- * @param {Number} capacity
- * @example
- *
- * // 1. create a SpriteBatchNode with image path
- * var spriteBatchNode = new cc.SpriteBatchNode("res/animations/grossini.png", 50);
- *
- * // 2. create a SpriteBatchNode with texture
- * var texture = cc.textureCache.addImage("res/animations/grossini.png");
- * var spriteBatchNode = new cc.SpriteBatchNode(texture,50);
- */
-cc.SpriteBatchNode = _ccsg.Node.extend(/** @lends cc.SpriteBatchNode# */{
- _blendFunc: null,
- _texture: null,
- _className: "SpriteBatchNode",
-
- ctor: function (fileImage) {
- _ccsg.Node.prototype.ctor.call(this);
- this._blendFunc = new cc.BlendFunc(cc.macro.BLEND_SRC, cc.macro.BLEND_DST);
-
- var texture2D;
- if (cc.js.isString(fileImage)) {
- texture2D = cc.textureCache.getTextureForKey(fileImage);
- if (!texture2D)
- texture2D = cc.textureCache.addImage(fileImage);
- }else if (fileImage instanceof cc.Texture2D)
- texture2D = fileImage;
-
- texture2D && this.initWithTexture(texture2D);
- },
-
- // property
-
- /**
- *
- * Initializes a cc.SpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children.
- * The capacity will be increased in 33% in runtime if it run out of space.
- * The file will be loaded using the TextureMgr.
- * Please pass parameters to constructor to initialize the sprite batch node, do not call this function yourself.
- *
- * @param {String} fileImage
- * @return {Boolean}
- */
- initWithFile: function (fileImage) {
- var texture2D = cc.textureCache.getTextureForKey(fileImage) || cc.textureCache.addImage(fileImage);
- return this.initWithTexture(texture2D);
- },
-
- /**
- * Removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter.
- * @warning Removing a child from a cc.SpriteBatchNode is very slow
- * @param {Number} index
- * @param {Boolean} doCleanup
- */
- removeChildAtIndex: function (index, doCleanup) {
- this.removeChild(this._children[index], doCleanup);
- },
-
- /**
- * Sets the source and destination blending function for the texture
- * @param {Number | cc.BlendFunc} src
- * @param {Number} dst
- */
- setBlendFunc: function (src, dst) {
- if (dst === undefined)
- this._blendFunc = src;
- else
- this._blendFunc = {src: src, dst: dst};
- },
-
- /**
- * Returns the blending function used for the texture
- * @return {cc.BlendFunc}
- */
- getBlendFunc: function () {
- return new cc.BlendFunc(this._blendFunc.src,this._blendFunc.dst);
- },
-
- /**
- *
- * Updates a quad at a certain index into the texture atlas. The CCSprite won't be added into the children array.
- * This method should be called only when you are dealing with very big AtlasSrite and when most of the _ccsg.Sprite won't be updated.
- * For example: a tile map (cc.TMXMap) or a label with lots of characters (BitmapFontAtlas)
- *
- * @function
- * @param {_ccsg.Sprite} sprite
- * @param {Number} index
- */
- updateQuadFromSprite: function (sprite, index) {
- cc.assertID(sprite, 2623);
- if (!(sprite instanceof _ccsg.Sprite)) {
- cc.log(2616);
- return;
- }
-
- //
- // update the quad directly. Don't add the sprite to the scene graph
- //
- sprite.dirty = true;
- // UpdateTransform updates the textureAtlas quad
- sprite._renderCmd.transform(this._renderCmd, true);
- },
-
- /**
- * Add child at the end
- * @function
- * @param {_ccsg.Sprite} sprite
- */
- appendChild: function (sprite) {
- this.sortAllChildren();
- var lastLocalZOrder = this._children[this._children.length-1]._localZOrder;
- this.addChild(sprite. lastLocalZOrder + 1);
- },
-
- /**
- * Set the texture property
- * @function
- * @param {Texture2D} tex
- * @return {Boolean}
- */
- initWithTexture: function (tex) {
- this.setTexture(tex);
- return true;
- },
-
- // CCTextureProtocol
- /**
- * Returns texture of the sprite batch node
- * @function
- * @return {Texture2D}
- */
- getTexture: function () {
- return this._texture;
- },
-
- /**
- * Sets the texture of the sprite batch node.
- * @function
- * @param {Texture2D} texture
- */
- setTexture: function(texture){
- this._texture = texture;
-
- if (texture.loaded) {
- var children = this._children, i, len = children.length;
- for (i = 0; i < len; ++i) {
- children[i].setTexture(texture);
- }
- }
- else {
- texture.addEventListener("load", function(){
- var children = this._children, i, len = children.length;
- for (i = 0; i < len; ++i) {
- children[i].setTexture(texture);
- }
- }, this);
- }
- },
-
- setShaderProgram: function (newShaderProgram) {
- this._renderCmd.setShaderProgram(newShaderProgram);
- var children = this._children, i, len = children.length;
- for (i = 0; i < len; ++i) {
- children[i].setShaderProgram(newShaderProgram);
- }
- },
-
- /**
- * Add child to the sprite batch node (override addChild of ccsg.Node)
- * @function
- * @override
- * @param {_ccsg.Sprite} child
- * @param {Number} [zOrder]
- * @param {Number} [tag]
- */
- addChild: function (child, zOrder, tag) {
- cc.assertID(child !== undefined, 2614);
-
- if(!this._isValidChild(child))
- return;
-
- zOrder = (zOrder === undefined) ? child.zIndex : zOrder;
- tag = (tag === undefined) ? child.tag : tag;
- _ccsg.Node.prototype.addChild.call(this, child, zOrder, tag);
-
- // Apply shader
- if (this._renderCmd._shaderProgram) {
- child.shaderProgram = this._renderCmd._shaderProgram;
- }
- },
-
- _isValidChild: function (child) {
- if (!(child instanceof _ccsg.Sprite)) {
- cc.logID(2618);
- return false;
- }
- if (child.texture !== this._texture) {
- cc.logID(2619);
- return false;
- }
- return true;
- }
-});
-
-var _p = cc.SpriteBatchNode.prototype;
-
-// Override properties
-cc.defineGetterSetter(_p, "texture", _p.getTexture, _p.setTexture);
-cc.defineGetterSetter(_p, "shaderProgram", _p.getShaderProgram, _p.setShaderProgram);
diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js
index 2f74f094e62..ccfae81c5af 100644
--- a/cocos2d/deprecated.js
+++ b/cocos2d/deprecated.js
@@ -472,8 +472,6 @@ if (CC_DEV) {
'textureLoaded',
'setBlendFunc',
'getBlendFunc',
- 'setState',
- 'getState',
'resizableSpriteWithCapInsets',
'flippedX',
'flippedY',
@@ -554,42 +552,6 @@ if (CC_DEV) {
});
}
- if (!CC_JSB) {
- // _ccsg.Node
- markAsRemoved(_ccsg.Node, [
- '_normalizedPositionDirty',
- '_normalizedPosition',
- '_usingNormalizedPosition',
- 'grid',
- 'userData',
- 'userObject',
- 'actionManager',
- 'getActionManager',
- 'setActionManager',
- 'getNormalizedPosition',
- 'setNormalizedPosition',
- 'getCamera',
- 'getUserData',
- 'setUserData',
- 'getUserObject',
- 'setUserObject',
- 'getComponent',
- 'addComponent',
- 'removeComponent',
- 'removeAllComponents',
- 'enumerateChildren',
- 'setCameraMask',
- 'getCameraMask'
- ], '_ccsg.Node');
- }
-
- js.obsolete(_ccsg.Node.prototype, '_ccsg.Node.ignoreAnchorPointForPosition', 'setIgnoreAnchorPointForPosition');
-
- js.obsoletes(cc.Scale9Sprite.prototype, 'cc.Scale9Sprite', {
- setPreferredSize: 'setContentSize',
- getPreferredSize: 'getContentSize',
- });
-
if (cc.ActionManager) {
js.obsoletes(cc.ActionManager.prototype, 'cc.ActionManager', {
'numberOfRunningActionsInTarget' : 'getNumberOfRunningActionsInTarget'
diff --git a/cocos2d/index.js b/cocos2d/index.js
index ba06b83849e..8af92f3368e 100644
--- a/cocos2d/index.js
+++ b/cocos2d/index.js
@@ -3,19 +3,5 @@ require('./core/CCGame');
// ensure modular-cocos2d can determine whether action module is included
require('./actions');
-require('./core/base-nodes/CCSGNode');
-require('./core/base-nodes/CCSGNodeBaseRenderCmd');
-require('./core/base-nodes/CCSGNodeCanvasRenderCmd');
-require('./core/base-nodes/CCSGNodeWebGLRenderCmd');
-require('./core/scenes/CCSGScene');
require('./core/CCConfiguration');
-require('./core/sprites/CCSGSprite');
-require('./core/sprites/CCSGSpriteCanvasRenderCmd');
-require('./core/sprites/CCSGSpriteWebGLRenderCmd');
-require('./core/sprites/CCScale9Sprite');
-require('./core/sprites/CCScale9SpriteCanvasRenderCmd');
-require('./core/sprites/CCScale9SpriteWebGLRenderCmd');
-require('./core/sprites/CCSpriteBatchNode');
-require('./render-texture/CCRenderTexture');
-require('./render-texture/CCRenderTextureCanvasRenderCmd');
-require('./render-texture/CCRenderTextureWebGLRenderCmd');
+// require('./render-texture/CCRenderTexture');
diff --git a/cocos2d/particle/CCParticleSystem.js b/cocos2d/particle/CCParticleSystem.js
index 75a7d6d53a4..2545c780bb5 100644
--- a/cocos2d/particle/CCParticleSystem.js
+++ b/cocos2d/particle/CCParticleSystem.js
@@ -24,9 +24,9 @@
****************************************************************************/
require('./CCParticleAsset');
-require('./CCSGParticleSystem');
-require('./CCSGParticleSystemCanvasRenderCmd');
-require('./CCSGParticleSystemWebGLRenderCmd');
+// require('./CCSGParticleSystem');
+// require('./CCSGParticleSystemCanvasRenderCmd');
+// require('./CCSGParticleSystemWebGLRenderCmd');
var BlendFactor = cc.BlendFunc.BlendFactor;
/**
diff --git a/cocos2d/shape-nodes/CCDrawNode.js b/cocos2d/shape-nodes/CCDrawNode.js
deleted file mode 100644
index 58685525213..00000000000
--- a/cocos2d/shape-nodes/CCDrawNode.js
+++ /dev/null
@@ -1,844 +0,0 @@
-/****************************************************************************
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
- Copyright (c) 2012 Scott Lembcke and Howling Moon Software
-
- 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.
- ****************************************************************************/
-
-var __t = function (v) {
- return {u: v.x, v: v.y};
-};
-
-/**
- * CCDrawNode
- * Node that draws dots, segments and polygons.
- * Faster than the "drawing primitives" since they it draws everything in one single batch.
- * @class
- * @name cc.DrawNode
- * @extends _ccsg.Node
- */
-cc.DrawNode = _ccsg.Node.extend(/** @lends cc.DrawNode# */{
-//TODO need refactor
-
- _buffer: null,
- _blendFunc: null,
- _lineWidth: 1,
- _drawColor: null,
-
- /**
- * Gets the blend func
- * @returns {Object}
- */
- getBlendFunc: function () {
- return this._blendFunc;
- },
-
- /**
- * Set the blend func
- * @param blendFunc
- * @param dst
- */
- setBlendFunc: function (blendFunc, dst) {
- if (dst === undefined) {
- this._blendFunc.src = blendFunc.src;
- this._blendFunc.dst = blendFunc.dst;
- } else {
- this._blendFunc.src = blendFunc;
- this._blendFunc.dst = dst;
- }
- },
-
- /**
- * line width setter
- * @param {Number} width
- */
- setLineWidth: function (width) {
- this._lineWidth = width;
- },
-
- /**
- * line width getter
- * @returns {Number}
- */
- getLineWidth: function () {
- return this._lineWidth;
- },
-
- /**
- * draw color setter
- * @param {cc.Color} color
- */
- setDrawColor: function (color) {
- var locDrawColor = this._drawColor;
- locDrawColor.r = color.r;
- locDrawColor.g = color.g;
- locDrawColor.b = color.b;
- locDrawColor.a = (color.a == null) ? 255 : color.a;
- },
-
- /**
- * draw color getter
- * @returns {cc.Color}
- */
- getDrawColor: function () {
- return cc.color(this._drawColor.r, this._drawColor.g, this._drawColor.b, this._drawColor.a);
- }
-});
-
-cc.DrawNode.TYPE_DOT = 0;
-cc.DrawNode.TYPE_SEGMENT = 1;
-cc.DrawNode.TYPE_POLY = 2;
-
-cc.game.once(cc.game.EVENT_RENDERER_INITED, function () {
- var proto = cc.DrawNode.prototype;
- if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
-
- cc._DrawNodeElement = function (type, verts, fillColor, lineWidth, lineColor, lineCap, isClosePolygon, isFill, isStroke) {
- var _t = this;
- _t.type = type;
- _t.verts = verts || null;
- _t.fillColor = fillColor || null;
- _t.lineWidth = lineWidth || 0;
- _t.lineColor = lineColor || null;
- _t.lineCap = lineCap || "butt";
- _t.isClosePolygon = isClosePolygon || false;
- _t.isFill = isFill || false;
- _t.isStroke = isStroke || false;
- };
-
- proto._className = "DrawNodeCanvas";
-
- /**
- * The cc.DrawNodeCanvas's constructor.
- * This function will automatically be invoked when you create a node using new construction: "var node = new cc.DrawNodeCanvas()".
- * Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.
- */
- proto.ctor = function () {
- _ccsg.Node.prototype.ctor.call(this);
- var locCmd = this._renderCmd;
- locCmd._buffer = this._buffer = [];
- locCmd._drawColor = this._drawColor = cc.color(255, 255, 255, 255);
- locCmd._blendFunc = this._blendFunc = new cc.BlendFunc(cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA);
-
- this.init();
- };
-
- /**
- * draws a rectangle given the origin and destination point measured in points.
- * @param {cc.Vec2} origin
- * @param {cc.Vec2} destination
- * @param {cc.Color} fillColor
- * @param {Number} lineWidth
- * @param {cc.Color} lineColor
- */
- proto.drawRect = function (origin, destination, fillColor, lineWidth, lineColor) {
- lineWidth = (lineWidth == null) ? this._lineWidth : lineWidth;
- lineColor = lineColor || this.getDrawColor();
- if(lineColor.a == null)
- lineColor.a = 255;
-
- var vertices = [
- origin,
- cc.p(destination.x, origin.y),
- destination,
- cc.p(origin.x, destination.y)
- ];
- var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
- element.verts = vertices;
- element.lineWidth = lineWidth;
- element.lineColor = lineColor;
- element.isClosePolygon = true;
- element.isStroke = true;
- element.lineCap = "butt";
- element.fillColor = fillColor;
- if (fillColor) {
- if(fillColor.a == null)
- fillColor.a = 255;
- element.isFill = true;
- }
- this._buffer.push(element);
- };
-
- /**
- * draws a circle given the center, radius and number of segments.
- * @override
- * @param {cc.Vec2} center center of circle
- * @param {Number} radius
- * @param {Number} angle angle in radians
- * @param {Number} segments
- * @param {Boolean} drawLineToCenter
- * @param {Number} lineWidth
- * @param {cc.Color} color
- */
- proto.drawCircle = function (center, radius, angle, segments, drawLineToCenter, lineWidth, color) {
- lineWidth = lineWidth || this._lineWidth;
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
-
- var coef = 2.0 * Math.PI / segments;
- var vertices = [];
- for (var i = 0; i <= segments; i++) {
- var rads = i * coef;
- var j = radius * Math.cos(rads + angle) + center.x;
- var k = radius * Math.sin(rads + angle) + center.y;
- vertices.push(cc.p(j, k));
- }
- if (drawLineToCenter) {
- vertices.push(cc.p(center.x, center.y));
- }
-
- var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
- element.verts = vertices;
- element.lineWidth = lineWidth;
- element.lineColor = color;
- element.isClosePolygon = true;
- element.isStroke = true;
- this._buffer.push(element);
- };
-
- /**
- * draws a quad bezier path
- * @override
- * @param {cc.Vec2} origin
- * @param {cc.Vec2} control
- * @param {cc.Vec2} destination
- * @param {Number} segments
- * @param {Number} lineWidth
- * @param {cc.Color} color
- */
- proto.drawQuadBezier = function (origin, control, destination, segments, lineWidth, color) {
- lineWidth = lineWidth || this._lineWidth;
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
-
- var vertices = [], t = 0.0;
- for (var i = 0; i < segments; i++) {
- var x = Math.pow(1 - t, 2) * origin.x + 2.0 * (1 - t) * t * control.x + t * t * destination.x;
- var y = Math.pow(1 - t, 2) * origin.y + 2.0 * (1 - t) * t * control.y + t * t * destination.y;
- vertices.push(cc.p(x, y));
- t += 1.0 / segments;
- }
- vertices.push(cc.p(destination.x, destination.y));
-
- var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
- element.verts = vertices;
- element.lineWidth = lineWidth;
- element.lineColor = color;
- element.isStroke = true;
- element.lineCap = "round";
- this._buffer.push(element);
- };
-
- /**
- * draws a cubic bezier path
- * @override
- * @param {cc.Vec2} origin
- * @param {cc.Vec2} control1
- * @param {cc.Vec2} control2
- * @param {cc.Vec2} destination
- * @param {Number} segments
- * @param {Number} lineWidth
- * @param {cc.Color} color
- */
- proto.drawCubicBezier = function (origin, control1, control2, destination, segments, lineWidth, color) {
- lineWidth = lineWidth || this._lineWidth;
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
-
- var vertices = [], t = 0;
- for (var i = 0; i < segments; i++) {
- var x = Math.pow(1 - t, 3) * origin.x + 3.0 * Math.pow(1 - t, 2) * t * control1.x + 3.0 * (1 - t) * t * t * control2.x + t * t * t * destination.x;
- var y = Math.pow(1 - t, 3) * origin.y + 3.0 * Math.pow(1 - t, 2) * t * control1.y + 3.0 * (1 - t) * t * t * control2.y + t * t * t * destination.y;
- vertices.push(cc.p(x, y));
- t += 1.0 / segments;
- }
- vertices.push(cc.p(destination.x, destination.y));
-
- var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
- element.verts = vertices;
- element.lineWidth = lineWidth;
- element.lineColor = color;
- element.isStroke = true;
- element.lineCap = "round";
- this._buffer.push(element);
- };
-
- /**
- * draw a CatmullRom curve
- * @override
- * @param {Array} points
- * @param {Number} segments
- * @param {Number} lineWidth
- * @param {cc.Color} color
- */
- proto.drawCatmullRom = function (points, segments, lineWidth, color) {
- this.drawCardinalSpline(points, 0.5, segments, lineWidth, color);
- };
-
- /**
- * draw a cardinal spline path
- * @override
- * @param {Array} config
- * @param {Number} tension
- * @param {Number} segments
- * @param {Number} lineWidth
- * @param {cc.Color} color
- */
- proto.drawCardinalSpline = function (config, tension, segments, lineWidth, color) {
- lineWidth = lineWidth || this._lineWidth;
- color = color || this.getDrawColor();
- if(color.a == null)
- color.a = 255;
-
- var vertices = [], p, lt, deltaT = 1.0 / config.length;
- for (var i = 0; i < segments + 1; i++) {
- var dt = i / segments;
- // border
- if (dt === 1) {
- p = config.length - 1;
- lt = 1;
- } else {
- p = 0 | (dt / deltaT);
- lt = (dt - deltaT * p) / deltaT;
- }
-
- // Interpolate
- var newPos = cc.cardinalSplineAt(
- cc.getControlPointAt(config, p - 1),
- cc.getControlPointAt(config, p - 0),
- cc.getControlPointAt(config, p + 1),
- cc.getControlPointAt(config, p + 2),
- tension, lt);
- vertices.push(newPos);
- }
-
- var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
- element.verts = vertices;
- element.lineWidth = lineWidth;
- element.lineColor = color;
- element.isStroke = true;
- element.lineCap = "round";
- this._buffer.push(element);
- };
-
- /**
- * draw a dot at a position, with a given radius and color
- * @param {cc.Vec2} pos
- * @param {Number} radius
- * @param {cc.Color} color
- */
- proto.drawDot = function (pos, radius, color) {
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
- var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_DOT);
- element.verts = [pos];
- element.lineWidth = radius;
- element.fillColor = color;
- this._buffer.push(element);
- };
-
- /**
- * draws an array of points.
- * @override
- * @param {Array} points point of array
- * @param {Number} radius
- * @param {cc.Color} color
- */
- proto.drawDots = function(points, radius, color){
- if(!points || points.length == 0)
- return;
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
- for(var i = 0, len = points.length; i < len; i++)
- this.drawDot(points[i], radius, color);
- };
-
- /**
- * draw a segment with a radius and color
- * @param {cc.Vec2} from
- * @param {cc.Vec2} to
- * @param {Number} lineWidth
- * @param {cc.Color} color
- */
- proto.drawSegment = function (from, to, lineWidth, color) {
- lineWidth = lineWidth || this._lineWidth;
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
- var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
- element.verts = [from, to];
- element.lineWidth = lineWidth * 2;
- element.lineColor = color;
- element.isStroke = true;
- element.lineCap = "round";
- this._buffer.push(element);
- };
-
- /**
- * draw a polygon with a fill color and line color without copying the vertex list
- * @param {Array} verts
- * @param {cc.Color} fillColor
- * @param {Number} lineWidth
- * @param {cc.Color} color
- */
- proto.drawPoly_ = function (verts, fillColor, lineWidth, color, notClosePoly) {
- lineWidth = (lineWidth == null ) ? this._lineWidth : lineWidth;
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
- var element = new cc._DrawNodeElement(cc.DrawNode.TYPE_POLY);
-
- element.verts = verts;
- element.fillColor = fillColor;
- element.lineWidth = lineWidth;
- element.lineColor = color;
- element.isClosePolygon = !notClosePoly;
- element.isStroke = true;
- element.lineCap = "round";
- if (fillColor)
- element.isFill = true;
- this._buffer.push(element);
- };
-
- /**
- * draw a polygon with a fill color and line color, copying the vertex list
- * @param {Array} verts
- * @param {cc.Color} fillColor
- * @param {Number} lineWidth
- * @param {cc.Color} color
- * @param {Boolean} notClosePoly
- */
- proto.drawPoly = function (verts, fillColor, lineWidth, color, notClosePoly) {
- var vertsCopy = [];
- for (var i=0; i < verts.length; i++) {
- vertsCopy.push(cc.p(verts[i].x, verts[i].y));
- }
- return this.drawPoly_(vertsCopy, fillColor, lineWidth, color, notClosePoly);
- };
-
- /**
- * Clear the geometry in the node's buffer.
- */
- proto.clear = function () {
- this._buffer.length = 0;
- };
-
- require('./CCDrawNodeCanvasRenderCmd');
-
- proto._createRenderCmd = function () {
- return new cc.DrawNode.CanvasRenderCmd(this);
- };
- }
- else if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
-
- proto._bufferCapacity = 0;
-
- proto._trianglesArrayBuffer = null;
- proto._trianglesWebBuffer = null;
- proto._trianglesReader = null;
-
- proto._dirty = false;
- proto._className = "DrawNodeWebGL";
-
- proto.ctor = function () {
- _ccsg.Node.prototype.ctor.call(this);
- this._buffer = [];
- this._blendFunc = new cc.BlendFunc(cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA);
- this._drawColor = cc.color(255,255,255,255);
-
- this.init();
- };
-
- proto.init = function () {
- if (_ccsg.Node.prototype.init.call(this)) {
- this.shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_POSITION_LENGTHTEXTURECOLOR);
- this._ensureCapacity(64);
- this._trianglesWebBuffer = cc._renderContext.createBuffer();
- this._dirty = true;
- return true;
- }
- return false;
- };
-
- proto.drawRect = function (origin, destination, fillColor, lineWidth, lineColor) {
- lineWidth = (lineWidth == null) ? this._lineWidth : lineWidth;
- lineColor = lineColor || this.getDrawColor();
- if (lineColor.a == null)
- lineColor.a = 255;
- var vertices = [origin, cc.p(destination.x, origin.y), destination, cc.p(origin.x, destination.y)];
- if(fillColor == null)
- this._drawSegments(vertices, lineWidth, lineColor, true);
- else
- this.drawPoly(vertices, fillColor, lineWidth, lineColor);
- };
-
- proto.drawCircle = function (center, radius, angle, segments, drawLineToCenter, lineWidth, color) {
- lineWidth = lineWidth || this._lineWidth;
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
- var coef = 2.0 * Math.PI / segments, vertices = [], i, len;
- for (i = 0; i <= segments; i++) {
- var rads = i * coef;
- var j = radius * Math.cos(rads + angle) + center.x;
- var k = radius * Math.sin(rads + angle) + center.y;
- vertices.push(cc.p(j, k));
- }
- if (drawLineToCenter)
- vertices.push(cc.p(center.x, center.y));
-
- lineWidth *= 0.5;
- for (i = 0, len = vertices.length; i < len - 1; i++)
- this.drawSegment(vertices[i], vertices[i + 1], lineWidth, color);
- };
-
- proto.drawQuadBezier = function (origin, control, destination, segments, lineWidth, color) {
- lineWidth = lineWidth || this._lineWidth;
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
- var vertices = [], t = 0.0;
- for (var i = 0; i < segments; i++) {
- var x = Math.pow(1 - t, 2) * origin.x + 2.0 * (1 - t) * t * control.x + t * t * destination.x;
- var y = Math.pow(1 - t, 2) * origin.y + 2.0 * (1 - t) * t * control.y + t * t * destination.y;
- vertices.push(cc.p(x, y));
- t += 1.0 / segments;
- }
- vertices.push(cc.p(destination.x, destination.y));
- this._drawSegments(vertices, lineWidth, color, false);
- };
-
- proto.drawCubicBezier = function (origin, control1, control2, destination, segments, lineWidth, color) {
- lineWidth = lineWidth || this._lineWidth;
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
- var vertices = [], t = 0;
- for (var i = 0; i < segments; i++) {
- var x = Math.pow(1 - t, 3) * origin.x + 3.0 * Math.pow(1 - t, 2) * t * control1.x + 3.0 * (1 - t) * t * t * control2.x + t * t * t * destination.x;
- var y = Math.pow(1 - t, 3) * origin.y + 3.0 * Math.pow(1 - t, 2) * t * control1.y + 3.0 * (1 - t) * t * t * control2.y + t * t * t * destination.y;
- vertices.push(cc.p(x, y));
- t += 1.0 / segments;
- }
- vertices.push(cc.p(destination.x, destination.y));
- this._drawSegments(vertices, lineWidth, color, false);
- };
-
- proto.drawCatmullRom = function (points, segments, lineWidth, color) {
- this.drawCardinalSpline(points, 0.5, segments, lineWidth, color);
- };
-
- proto.drawCardinalSpline = function (config, tension, segments, lineWidth, color) {
- lineWidth = lineWidth || this._lineWidth;
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
- var vertices = [], p, lt, deltaT = 1.0 / config.length;
-
- for (var i = 0; i < segments + 1; i++) {
- var dt = i / segments;
-
- // border
- if (dt === 1) {
- p = config.length - 1;
- lt = 1;
- } else {
- p = 0 | (dt / deltaT);
- lt = (dt - deltaT * p) / deltaT;
- }
-
- // Interpolate
- var newPos = cc.cardinalSplineAt(
- cc.getControlPointAt(config, p - 1),
- cc.getControlPointAt(config, p - 0),
- cc.getControlPointAt(config, p + 1),
- cc.getControlPointAt(config, p + 2),
- tension, lt);
- vertices.push(newPos);
- }
-
- lineWidth *= 0.5;
- for (var j = 0, len = vertices.length; j < len - 1; j++)
- this.drawSegment(vertices[j], vertices[j + 1], lineWidth, color);
- };
-
- proto._render = function () {
- var gl = cc._renderContext;
-
- gl.bindBuffer(gl.ARRAY_BUFFER, this._trianglesWebBuffer);
- if (this._dirty) {
- gl.bufferData(gl.ARRAY_BUFFER, this._trianglesArrayBuffer, gl.STREAM_DRAW);
- this._dirty = false;
- }
- var triangleSize = cc.V2F_C4B_T2F.BYTES_PER_ELEMENT;
-
- gl.enableVertexAttribArray(cc.macro.VERTEX_ATTRIB_POSITION);
- gl.enableVertexAttribArray(cc.macro.VERTEX_ATTRIB_COLOR);
- gl.enableVertexAttribArray(cc.macro.VERTEX_ATTRIB_TEX_COORDS);
-
- // vertex
- gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, triangleSize, 0);
- // color
- gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, triangleSize, 8);
- // texcood
- gl.vertexAttribPointer(cc.macro.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, triangleSize, 12);
-
- gl.drawArrays(gl.TRIANGLES, 0, this._buffer.length * 3);
- cc.incrementGLDraws(1);
- //cc.checkGLErrorDebug();
- };
-
- proto._ensureCapacity = function(count){
- var _t = this;
- var locBuffer = _t._buffer;
- if(locBuffer.length + count > _t._bufferCapacity){
- var TriangleLength = cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT;
- _t._bufferCapacity += Math.max(_t._bufferCapacity, count);
- //re alloc
- if((locBuffer == null) || (locBuffer.length === 0)){
- //init
- _t._buffer = [];
- _t._trianglesArrayBuffer = new ArrayBuffer(TriangleLength * _t._bufferCapacity);
- _t._trianglesReader = new Uint8Array(_t._trianglesArrayBuffer);
- } else {
- var newTriangles = [];
- var newArrayBuffer = new ArrayBuffer(TriangleLength * _t._bufferCapacity);
- for(var i = 0; i < locBuffer.length;i++){
- newTriangles[i] = new cc.V2F_C4B_T2F_Triangle(locBuffer[i].a,locBuffer[i].b,locBuffer[i].c,
- newArrayBuffer, i * TriangleLength);
- }
- _t._trianglesReader = new Uint8Array(newArrayBuffer);
- _t._trianglesArrayBuffer = newArrayBuffer;
- _t._buffer = newTriangles;
- }
- }
- };
-
- proto.drawDot = function (pos, radius, color) {
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
- var c4bColor = {r: 0 | color.r, g: 0 | color.g, b: 0 | color.b, a: 0 | color.a};
- var a = {vertices: {x: pos.x - radius, y: pos.y - radius}, colors: c4bColor, texCoords: {u: -1.0, v: -1.0}};
- var b = {vertices: {x: pos.x - radius, y: pos.y + radius}, colors: c4bColor, texCoords: {u: -1.0, v: 1.0}};
- var c = {vertices: {x: pos.x + radius, y: pos.y + radius}, colors: c4bColor, texCoords: {u: 1.0, v: 1.0}};
- var d = {vertices: {x: pos.x + radius, y: pos.y - radius}, colors: c4bColor, texCoords: {u: 1.0, v: -1.0}};
-
- this._ensureCapacity(2*3);
-
- this._buffer.push(new cc.V2F_C4B_T2F_Triangle(a, b, c, this._trianglesArrayBuffer, this._buffer.length * cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT));
- this._buffer.push(new cc.V2F_C4B_T2F_Triangle(a, c, d, this._trianglesArrayBuffer, this._buffer.length * cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT));
- this._dirty = true;
- };
-
- proto.drawDots = function(points, radius,color) {
- if(!points || points.length === 0)
- return;
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
- for(var i = 0, len = points.length; i < len; i++)
- this.drawDot(points[i], radius, color);
- };
-
- proto.drawSegment = function (from, to, radius, color) {
- color = color || this.getDrawColor();
- if (color.a == null)
- color.a = 255;
- radius = radius || (this._lineWidth * 0.5);
- var vertexCount = 6*3;
- this._ensureCapacity(vertexCount);
-
- var c4bColor = {r: 0 | color.r, g: 0 | color.g, b: 0 | color.b, a: 0 | color.a};
- var a = cc.v2(from), b = cc.v2(to);
- var n = cc.pNormalize(cc.pPerp(cc.pSub(b, a))), t = cc.pPerp(n);
- var nw = cc.pMult(n, radius), tw = cc.pMult(t, radius);
-
- var v0 = cc.pSub(b, cc.pAdd(nw, tw));
- var v1 = cc.pAdd(b, cc.pSub(nw, tw));
- var v2 = cc.pSub(b, nw);
- var v3 = cc.pAdd(b, nw);
- var v4 = cc.pSub(a, nw);
- var v5 = cc.pAdd(a, nw);
- var v6 = cc.pSub(a, cc.pSub(nw, tw));
- var v7 = cc.pAdd(a, cc.pAdd(nw, tw));
-
- var TriangleLength = cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT, triangleBuffer = this._trianglesArrayBuffer, locBuffer = this._buffer;
- locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v0, colors: c4bColor, texCoords: __t(cc.pNeg(cc.pAdd(n, t)))},
- {vertices: v1, colors: c4bColor, texCoords: __t(cc.pSub(n, t))}, {vertices: v2, colors: c4bColor, texCoords: __t(cc.pNeg(n))},
- triangleBuffer, locBuffer.length * TriangleLength));
-
- locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v3, colors: c4bColor, texCoords: __t(n)},
- {vertices: v1, colors: c4bColor, texCoords: __t(cc.pSub(n, t))}, {vertices: v2, colors: c4bColor, texCoords: __t(cc.pNeg(n))},
- triangleBuffer, locBuffer.length * TriangleLength));
-
- locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v3, colors: c4bColor, texCoords: __t(n)},
- {vertices: v4, colors: c4bColor, texCoords: __t(cc.pNeg(n))}, {vertices: v2, colors: c4bColor, texCoords: __t(cc.pNeg(n))},
- triangleBuffer, locBuffer.length * TriangleLength));
-
- locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v3, colors: c4bColor, texCoords: __t(n)},
- {vertices: v4, colors: c4bColor, texCoords: __t(cc.pNeg(n))}, {vertices: v5, colors: c4bColor, texCoords: __t(n)},
- triangleBuffer, locBuffer.length * TriangleLength));
-
- locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v6, colors: c4bColor, texCoords: __t(cc.pSub(t, n))},
- {vertices: v4, colors: c4bColor, texCoords: __t(cc.pNeg(n))}, {vertices: v5, colors: c4bColor, texCoords: __t(n)},
- triangleBuffer, locBuffer.length * TriangleLength));
-
- locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: v6, colors: c4bColor, texCoords: __t(cc.pSub(t, n))},
- {vertices: v7, colors: c4bColor, texCoords: __t(cc.pAdd(n, t))}, {vertices: v5, colors: c4bColor, texCoords: __t(n)},
- triangleBuffer, locBuffer.length * TriangleLength));
- this._dirty = true;
- };
-
- proto.drawPoly = function (verts, fillColor, borderWidth, borderColor, notClosePoly) {
- if(fillColor == null){
- this._drawSegments(verts, borderWidth, borderColor, !notClosePoly);
- return;
- }
- if (fillColor.a == null)
- fillColor.a = 255;
- if (borderColor.a == null)
- borderColor.a = 255;
- borderWidth = (borderWidth == null)? this._lineWidth : borderWidth;
- borderWidth *= 0.5;
- var c4bFillColor = {r: 0 | fillColor.r, g: 0 | fillColor.g, b: 0 | fillColor.b, a: 0 | fillColor.a};
- var c4bBorderColor = {r: 0 | borderColor.r, g: 0 | borderColor.g, b: 0 | borderColor.b, a: 0 | borderColor.a};
- var extrude = [], i, v0, v1, v2, count = verts.length;
- for (i = 0; i < count; i++) {
- v0 = cc.v2(verts[(i - 1 + count) % count]);
- v1 = cc.v2(verts[i]);
- v2 = cc.v2(verts[(i + 1) % count]);
- var n1 = cc.pNormalize(cc.pPerp(cc.pSub(v1, v0)));
- var n2 = cc.pNormalize(cc.pPerp(cc.pSub(v2, v1)));
- var offset = cc.pMult(cc.pAdd(n1, n2), 1.0 / (cc.pDot(n1, n2) + 1.0));
- extrude[i] = {offset: offset, n: n2};
- }
- var outline = (borderWidth > 0.0), triangleCount = 3 * count - 2, vertexCount = 3 * triangleCount;
- this._ensureCapacity(vertexCount);
-
- var triangleBytesLen = cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT, trianglesBuffer = this._trianglesArrayBuffer;
- var locBuffer = this._buffer;
-
- var va, vb, vc;
- for (i = 0; i < count - 2; i++) {
- va = {vertices: verts[0], colors: c4bFillColor, texCoords: __t(cc.v2())};
- vb = {vertices: verts[i + 1], colors: c4bFillColor, texCoords: __t(cc.v2())};
- vc = {vertices: verts[i + 2], colors: c4bFillColor, texCoords: __t(cc.v2())};
- locBuffer.push(new cc.V2F_C4B_T2F_Triangle(va, vb, vc, trianglesBuffer, locBuffer.length * triangleBytesLen));
- }
- if (outline) {
- for (i = 0; i < count; i++) {
- var j = (i + 1) % count;
- v0 = cc.v2(verts[i]);
- v1 = cc.v2(verts[j]);
-
- var n0 = extrude[i].n;
- var offset0 = extrude[i].offset;
- var offset1 = extrude[j].offset;
- var inner0 = cc.pSub(v0, cc.pMult(offset0, borderWidth));
- var inner1 = cc.pSub(v1, cc.pMult(offset1, borderWidth));
- var outer0 = cc.pAdd(v0, cc.pMult(offset0, borderWidth));
- var outer1 = cc.pAdd(v1, cc.pMult(offset1, borderWidth));
-
- va = { vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0)) };
- vb = { vertices: inner1, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0)) };
- vc = { vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0) };
- locBuffer.push(new cc.V2F_C4B_T2F_Triangle(va, vb, vc, trianglesBuffer, locBuffer.length * triangleBytesLen));
-
- va = { vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0)) };
- vb = { vertices: outer0, colors: c4bBorderColor, texCoords: __t(n0) };
- vc = { vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0) };
- locBuffer.push(new cc.V2F_C4B_T2F_Triangle(va, vb, vc, trianglesBuffer, locBuffer.length * triangleBytesLen));
- }
- }
- extrude = null;
- this._dirty = true;
- };
-
- proto._drawSegments = function(verts, borderWidth, borderColor, closePoly){
- borderWidth = (borderWidth == null) ? this._lineWidth : borderWidth;
- borderColor = borderColor || this._drawColor;
- if(borderColor.a == null)
- borderColor.a = 255;
- borderWidth *= 0.5;
- if (borderWidth <= 0)
- return;
-
- var c4bBorderColor = {r: 0 | borderColor.r, g: 0 | borderColor.g, b: 0 | borderColor.b, a: 0 | borderColor.a };
- var extrude = [], i, v0, v1, v2, count = verts.length;
- for (i = 0; i < count; i++) {
- v0 = cc.v2(verts[(i - 1 + count) % count]);
- v1 = cc.v2(verts[i]);
- v2 = cc.v2(verts[(i + 1) % count]);
- var n1 = cc.pNormalize(cc.pPerp(cc.pSub(v1, v0)));
- var n2 = cc.pNormalize(cc.pPerp(cc.pSub(v2, v1)));
- var offset = cc.pMult(cc.pAdd(n1, n2), 1.0 / (cc.pDot(n1, n2) + 1.0));
- extrude[i] = {offset: offset, n: n2};
- }
-
- var triangleCount = 3 * count - 2, vertexCount = 3 * triangleCount;
- this._ensureCapacity(vertexCount);
-
- var triangleBytesLen = cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT, trianglesBuffer = this._trianglesArrayBuffer;
- var locBuffer = this._buffer;
- var len = closePoly ? count : count - 1;
- for (i = 0; i < len; i++) {
- var j = (i + 1) % count;
- v0 = cc.v2(verts[i]);
- v1 = cc.v2(verts[j]);
-
- var n0 = extrude[i].n;
- var offset0 = extrude[i].offset;
- var offset1 = extrude[j].offset;
- var inner0 = cc.pSub(v0, cc.pMult(offset0, borderWidth));
- var inner1 = cc.pSub(v1, cc.pMult(offset1, borderWidth));
- var outer0 = cc.pAdd(v0, cc.pMult(offset0, borderWidth));
- var outer1 = cc.pAdd(v1, cc.pMult(offset1, borderWidth));
- locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))},
- {vertices: inner1, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))}, {vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0)},
- trianglesBuffer, locBuffer.length * triangleBytesLen));
- locBuffer.push(new cc.V2F_C4B_T2F_Triangle({vertices: inner0, colors: c4bBorderColor, texCoords: __t(cc.pNeg(n0))},
- {vertices: outer0, colors: c4bBorderColor, texCoords: __t(n0)}, {vertices: outer1, colors: c4bBorderColor, texCoords: __t(n0)},
- trianglesBuffer, locBuffer.length * triangleBytesLen));
- }
- extrude = null;
- this._dirty = true;
- };
-
- proto.clear = function () {
- this._buffer.length = 0;
- this._dirty = true;
- };
-
- require('./CCDrawNodeWebGLRenderCmd');
-
- proto._createRenderCmd = function () {
- return new cc.DrawNode.WebGLRenderCmd(this);
- };
- }
-});
diff --git a/cocos2d/shape-nodes/CCDrawNodeCanvasRenderCmd.js b/cocos2d/shape-nodes/CCDrawNodeCanvasRenderCmd.js
deleted file mode 100644
index 716c7996a36..00000000000
--- a/cocos2d/shape-nodes/CCDrawNodeCanvasRenderCmd.js
+++ /dev/null
@@ -1,126 +0,0 @@
-/****************************************************************************
- 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.
- ****************************************************************************/
-
-cc.DrawNode.CanvasRenderCmd = function(renderableObject){
- this._rootCtor(renderableObject);
- this._needDraw = true;
- this._buffer = null;
- this._drawColor = null;
- this._blendFunc = null;
-};
-
-var proto = cc.DrawNode.CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
-proto.constructor = cc.DrawNode.CanvasRenderCmd;
-
-proto.rendering = function (ctx, scaleX, scaleY) {
- var wrapper = ctx || cc._renderContext, context = wrapper.getContext(), node = this._node;
- var alpha = node._displayedOpacity / 255;
- if (alpha === 0)
- return;
-
- wrapper.setTransform(this._worldTransform, scaleX, scaleY);
-
- //context.save();
- wrapper.setGlobalAlpha(alpha);
- if ((this._blendFunc && (this._blendFunc.src === cc.macro.SRC_ALPHA) && (this._blendFunc.dst === cc.macro.ONE)))
- wrapper.setCompositeOperation('lighter'); //todo: need refactor
- var locBuffer = this._buffer;
- for (var i = 0, len = locBuffer.length; i < len; i++) {
- var element = locBuffer[i];
- switch (element.type) {
- case cc.DrawNode.TYPE_DOT:
- this._drawDot(wrapper, element, scaleX, scaleY);
- break;
- case cc.DrawNode.TYPE_SEGMENT:
- this._drawSegment(wrapper, element, scaleX, scaleY);
- break;
- case cc.DrawNode.TYPE_POLY:
- this._drawPoly(wrapper, element, scaleX, scaleY);
- break;
- }
- }
- //context.restore(); //todo It can be reserve
-};
-
-proto._drawDot = function (wrapper, element, scaleX, scaleY) {
- var locColor = element.fillColor, locPos = element.verts[0], locRadius = element.lineWidth;
-
- var ctx = wrapper.getContext();
- wrapper.setFillStyle("rgba(" + (0 | locColor.r) + "," + (0 | locColor.g) + "," + (0 | locColor.b) + "," + locColor.a / 255 + ")");
-
- ctx.beginPath();
- ctx.arc(locPos.x, -locPos.y, locRadius, 0, Math.PI * 2, false);
- ctx.closePath();
- ctx.fill();
-};
-
-proto._drawSegment = function (wrapper, element, scaleX, scaleY) {
- var locColor = element.lineColor;
- var locFrom = element.verts[0], locTo = element.verts[1];
- var locLineWidth = element.lineWidth, locLineCap = element.lineCap;
-
- var ctx = wrapper.getContext();
- wrapper.setStrokeStyle("rgba(" + (0 | locColor.r) + "," + (0 | locColor.g) + "," + (0 | locColor.b) + "," + locColor.a / 255 + ")");
-
- ctx.lineWidth = locLineWidth * scaleX;
- ctx.beginPath();
- ctx.lineCap = locLineCap;
- ctx.moveTo(locFrom.x, -locFrom.y);
- ctx.lineTo(locTo.x, -locTo.y);
- ctx.stroke();
-};
-
-proto._drawPoly = function (wrapper, element, scaleX, scaleY) {
- var locVertices = element.verts, locLineCap = element.lineCap;
- if (locVertices == null)
- return;
-
- var locFillColor = element.fillColor, locLineWidth = element.lineWidth;
- var locLineColor = element.lineColor, locIsClosePolygon = element.isClosePolygon;
- var locIsFill = element.isFill, locIsStroke = element.isStroke;
-
- var ctx = wrapper.getContext();
- var firstPoint = locVertices[0];
- ctx.lineCap = locLineCap;
- if (locFillColor)
- wrapper.setFillStyle("rgba(" + (0 | locFillColor.r) + "," + (0 | locFillColor.g) + ","
- + (0 | locFillColor.b) + "," + locFillColor.a / 255 + ")");
- if (locLineWidth)
- ctx.lineWidth = locLineWidth * scaleX;
- if (locLineColor)
- wrapper.setStrokeStyle("rgba(" + (0 | locLineColor.r) + "," + (0 | locLineColor.g) + ","
- + (0 | locLineColor.b) + "," + locLineColor.a / 255 + ")");
-
- ctx.beginPath();
- ctx.moveTo(firstPoint.x, -firstPoint.y);
- for (var i = 1, len = locVertices.length; i < len; i++)
- ctx.lineTo(locVertices[i].x, -locVertices[i].y);
-
- if (locIsClosePolygon)
- ctx.closePath();
- if (locIsFill)
- ctx.fill();
- if (locIsStroke)
- ctx.stroke();
-};
\ No newline at end of file
diff --git a/cocos2d/shape-nodes/CCDrawNodeWebGLRenderCmd.js b/cocos2d/shape-nodes/CCDrawNodeWebGLRenderCmd.js
deleted file mode 100644
index 1528bc0a79a..00000000000
--- a/cocos2d/shape-nodes/CCDrawNodeWebGLRenderCmd.js
+++ /dev/null
@@ -1,51 +0,0 @@
-/****************************************************************************
- 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.
- ****************************************************************************/
-
-cc.DrawNode.WebGLRenderCmd = function (renderableObject) {
- this._rootCtor(renderableObject);
- this._needDraw = true;
- this._matrix = new cc.math.Matrix4();
- this._matrix.identity();
-};
-
-cc.DrawNode.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
-cc.DrawNode.WebGLRenderCmd.prototype.constructor = cc.DrawNode.WebGLRenderCmd;
-
-cc.DrawNode.WebGLRenderCmd.prototype.rendering = function (ctx) {
- var node = this._node;
- if (node._buffer.length > 0) {
- var wt = this._worldTransform, mat = this._matrix.mat;
- mat[0] = wt.a;
- mat[4] = wt.c;
- mat[12] = wt.tx;
- mat[1] = wt.b;
- mat[5] = wt.d;
- mat[13] = wt.ty;
-
- cc.gl.blendFunc(node._blendFunc.src, node._blendFunc.dst);
- this._shaderProgram.use();
- this._shaderProgram._setUniformForMVPMatrixWithMat4(this._matrix);
- node._render();
- }
-};
diff --git a/extensions/dragonbones/CCArmatureDisplay.js b/extensions/dragonbones/CCArmatureDisplay.js
index 07a96a60487..ea4d628d6eb 100644
--- a/extensions/dragonbones/CCArmatureDisplay.js
+++ b/extensions/dragonbones/CCArmatureDisplay.js
@@ -23,7 +23,7 @@
****************************************************************************/
var EventTarget = require('../../cocos2d/core/event/event-target');
-require('../../cocos2d/shape-nodes/CCDrawNode');
+// require('../../cocos2d/shape-nodes/CCDrawNode');
dragonBones.CCArmatureDisplay = cc.Class({
name: 'dragonBones.CCArmatureDisplay',
diff --git a/extensions/spine/index.js b/extensions/spine/index.js
index 24056f4e07d..de6b95f8c40 100644
--- a/extensions/spine/index.js
+++ b/extensions/spine/index.js
@@ -114,10 +114,10 @@ if (!CC_EDITOR || !Editor.isMainProcess) {
sp.spine = require('./lib/spine');
require('./SGSkeletonTexture');
- require('./SGSkeleton');
- require('./SGSkeletonCanvasRenderCmd');
- require('./SGSkeletonWebGLRenderCmd');
- require('./SGSkeletonAnimation');
+ // require('./SGSkeleton');
+ // require('./SGSkeletonCanvasRenderCmd');
+ // require('./SGSkeletonWebGLRenderCmd');
+ // require('./SGSkeletonAnimation');
}
require('./SkeletonData');