mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
remove unused code
This commit is contained in:
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"files.exclude": {
|
||||
".git": true,
|
||||
"node_modules": true,
|
||||
".github": true
|
||||
},
|
||||
"search.exclude": {
|
||||
".git": true,
|
||||
"node_modules": true,
|
||||
".github": true,
|
||||
"bin": true
|
||||
}
|
||||
}
|
||||
+34
-36
@@ -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;
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
// // 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);
|
||||
}
|
||||
// // 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];
|
||||
|
||||
@@ -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);
|
||||
//}
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -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; i<children.length; i++){
|
||||
recursiveChild(children[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cc.Director._getInstance().on(cc.Director.EVENT_PROJECTION_CHANGED, function(){
|
||||
var stack = cc.director._scenesStack;
|
||||
for(var i=0; i<stack.length; i++)
|
||||
recursiveChild(stack[i]);
|
||||
});
|
||||
|
||||
_p.setProjection = function (projection) {
|
||||
var _t = this;
|
||||
var size = _t._winSizeInPoints;
|
||||
|
||||
_t.setViewport();
|
||||
|
||||
var view = _t._openGLView,
|
||||
ox = view._viewPortRect.x / view._scaleX,
|
||||
oy = view._viewPortRect.y / view._scaleY;
|
||||
|
||||
switch (projection) {
|
||||
case cc.Director.PROJECTION_2D:
|
||||
math.glMatrixMode(math.KM_GL_PROJECTION);
|
||||
math.glLoadIdentity();
|
||||
var orthoMatrix = math.Matrix4.createOrthographicProjection(
|
||||
0,
|
||||
size.width,
|
||||
0,
|
||||
size.height,
|
||||
-1024, 1024);
|
||||
math.glMultMatrix(orthoMatrix);
|
||||
math.glMatrixMode(math.KM_GL_MODELVIEW);
|
||||
math.glLoadIdentity();
|
||||
break;
|
||||
case cc.Director.PROJECTION_3D:
|
||||
var zeye = _t.getZEye();
|
||||
var matrixPerspective = new math.Matrix4(), matrixLookup = new math.Matrix4();
|
||||
math.glMatrixMode(math.KM_GL_PROJECTION);
|
||||
math.glLoadIdentity();
|
||||
|
||||
// issue #1334
|
||||
matrixPerspective = math.Matrix4.createPerspectiveProjection(60, size.width / size.height, 0.1, zeye * 2);
|
||||
|
||||
math.glMultMatrix(matrixPerspective);
|
||||
|
||||
var eye = new math.Vec3(-ox + size.width / 2, -oy + size.height / 2, zeye);
|
||||
var center = new math.Vec3(-ox + size.width / 2, -oy + size.height / 2, 0.0);
|
||||
var up = new math.Vec3(0.0, 1.0, 0.0);
|
||||
matrixLookup.lookAt(eye, center, up);
|
||||
math.glMultMatrix(matrixLookup);
|
||||
|
||||
math.glMatrixMode(math.KM_GL_MODELVIEW);
|
||||
math.glLoadIdentity();
|
||||
break;
|
||||
case cc.Director.PROJECTION_CUSTOM:
|
||||
if (_t._projectionDelegate)
|
||||
_t._projectionDelegate.updateProjection();
|
||||
break;
|
||||
default:
|
||||
cc.logID(1201);
|
||||
break;
|
||||
}
|
||||
_t._projection = projection;
|
||||
_t.emit(cc.Director.EVENT_PROJECTION_CHANGED, _t);
|
||||
cc.gl.setProjectionMatrixDirty();
|
||||
cc.renderer.childrenOrderDirty = true;
|
||||
};
|
||||
|
||||
_p.setDepthTest = function (on) {
|
||||
cc.renderer.setDepthTest(on);
|
||||
};
|
||||
|
||||
_p.setClearColor = function (clearColor) {
|
||||
var locClearColor = cc.renderer._clearColor;
|
||||
locClearColor.r = clearColor.r / 255;
|
||||
locClearColor.g = clearColor.g / 255;
|
||||
locClearColor.b = clearColor.b / 255;
|
||||
locClearColor.a = clearColor.a / 255;
|
||||
};
|
||||
|
||||
_p.setOpenGLView = function (openGLView) {
|
||||
var _t = this;
|
||||
// set size
|
||||
_t._winSizeInPoints.width = cc._canvas.width; //_t._openGLView.getDesignResolutionSize();
|
||||
_t._winSizeInPoints.height = cc._canvas.height;
|
||||
_t._openGLView = openGLView || cc.view;
|
||||
|
||||
// Configuration. Gather GPU info
|
||||
var conf = cc.configuration;
|
||||
conf.gatherGPUInfo();
|
||||
|
||||
// set size
|
||||
//_t._winSizeInPoints = _t._openGLView.getDesignResolutionSize();
|
||||
//_t._winSizeInPixels = cc.size(_t._winSizeInPoints.width * _t._contentScaleFactor, _t._winSizeInPoints.height * _t._contentScaleFactor);
|
||||
|
||||
//if (_t._openGLView != openGLView) {
|
||||
// because EAGLView is not kind of CCObject
|
||||
|
||||
//if (_t._openGLView)
|
||||
_t.setGLDefaultValues();
|
||||
|
||||
/* if (_t._contentScaleFactor != 1) {
|
||||
_t.updateContentScaleFactor();
|
||||
}*/
|
||||
|
||||
//}
|
||||
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);
|
||||
//}
|
||||
};
|
||||
|
||||
_p.getZEye = function () {
|
||||
return (this._winSizeInPoints.height / 1.1566 );
|
||||
};
|
||||
|
||||
_p.setViewport = function () {
|
||||
var view = this._openGLView;
|
||||
if (view) {
|
||||
var locWinSizeInPoints = this._winSizeInPoints;
|
||||
view.setViewPortInPoints(-view._viewPortRect.x/view._scaleX, -view._viewPortRect.y/view._scaleY, locWinSizeInPoints.width, locWinSizeInPoints.height);
|
||||
}
|
||||
};
|
||||
|
||||
_p.getOpenGLView = function () {
|
||||
return this._openGLView;
|
||||
};
|
||||
|
||||
_p.getProjection = function () {
|
||||
return this._projection;
|
||||
};
|
||||
|
||||
_p.setAlphaBlending = function (on) {
|
||||
if (on)
|
||||
cc.gl.blendFunc(cc.macro.BLEND_SRC, cc.macro.BLEND_DST);
|
||||
else
|
||||
cc.gl.blendFunc(cc.macro.ONE, cc.macro.ZERO);
|
||||
//cc.checkGLErrorDebug();
|
||||
};
|
||||
|
||||
_p.setGLDefaultValues = function () {
|
||||
var _t = this;
|
||||
_t.setAlphaBlending(true);
|
||||
_t.setProjection(_t._projection);
|
||||
|
||||
// set other opengl default values
|
||||
cc._renderContext.clearColor(0.0, 0.0, 0.0, 0.0);
|
||||
};
|
||||
});
|
||||
@@ -1,41 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013-2017 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.
|
||||
****************************************************************************/
|
||||
|
||||
var game = require('./CCGame');
|
||||
|
||||
/**
|
||||
* @property {DrawingPrimitive} _drawingUtil - drawing primitive of game engine
|
||||
* @private
|
||||
*/
|
||||
cc._drawingUtil = null;
|
||||
|
||||
game.once(game.EVENT_RENDERER_INITED, function () {
|
||||
if (cc._renderType === game.RENDER_TYPE_WEBGL) {
|
||||
cc._drawingUtil = new (require('./CCDrawingPrimitivesWebGL'))(cc._renderContext);
|
||||
}
|
||||
else {
|
||||
cc._drawingUtil = new (require('./CCDrawingPrimitivesCanvas'))(cc._renderContext);
|
||||
}
|
||||
});
|
||||
@@ -1,435 +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.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* Canvas of DrawingPrimitive implement version use for canvasMode
|
||||
* @class DrawingPrimitiveCanvas
|
||||
* @extends cc._Class
|
||||
* @param {CanvasRenderingContext2D} renderContext
|
||||
*/
|
||||
var DrawingPrimitiveCanvas = cc._Class.extend({
|
||||
_cacheArray:[],
|
||||
|
||||
/**
|
||||
* Constructor of DrawingPrimitiveCanvas
|
||||
* @param {cc.CanvasContextWrapper} renderContext
|
||||
*/
|
||||
ctor:function (renderContext) {
|
||||
this._renderContext = renderContext;
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a point given x and y coordinate measured in points
|
||||
* @override
|
||||
* @param {cc.Vec2} point
|
||||
* @param {Number} size
|
||||
*/
|
||||
drawPoint:function (point, size) {
|
||||
if (!size) {
|
||||
size = 1;
|
||||
}
|
||||
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
|
||||
var newPoint = cc.p(point.x * locScaleX, point.y * locScaleY);
|
||||
var ctx = this._renderContext.getContext();
|
||||
ctx.beginPath();
|
||||
ctx.arc(newPoint.x, -newPoint.y, size * locScaleX, 0, Math.PI * 2, false);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
},
|
||||
|
||||
/**
|
||||
* draws an array of points.
|
||||
* @override
|
||||
* @param {Array} points point of array
|
||||
* @param {Number} numberOfPoints
|
||||
* @param {Number} size
|
||||
*/
|
||||
drawPoints:function (points, numberOfPoints, size) {
|
||||
if (points == null)
|
||||
return;
|
||||
|
||||
if (!size) {
|
||||
size = 1;
|
||||
}
|
||||
var locContext = this._renderContext.getContext(),locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
|
||||
|
||||
locContext.beginPath();
|
||||
for (var i = 0, len = points.length; i < len; i++)
|
||||
locContext.arc(points[i].x * locScaleX, -points[i].y * locScaleY, size * locScaleX, 0, Math.PI * 2, false);
|
||||
locContext.closePath();
|
||||
locContext.fill();
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a line given the origin and destination point measured in points
|
||||
* @override
|
||||
* @param {cc.Vec2} origin
|
||||
* @param {cc.Vec2} destination
|
||||
*/
|
||||
drawLine:function (origin, destination) {
|
||||
var locContext = this._renderContext.getContext(), locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
|
||||
locContext.beginPath();
|
||||
locContext.moveTo(origin.x * locScaleX, -origin.y * locScaleY);
|
||||
locContext.lineTo(destination.x * locScaleX, -destination.y * locScaleY);
|
||||
locContext.closePath();
|
||||
locContext.stroke();
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a rectangle given the origin and destination point measured in points.
|
||||
* @param {cc.Vec2} origin
|
||||
* @param {cc.Vec2} destination
|
||||
*/
|
||||
drawRect:function (origin, destination) {
|
||||
//todo need optimize for performance
|
||||
this.drawLine(cc.p(origin.x, origin.y), cc.p(destination.x, origin.y));
|
||||
this.drawLine(cc.p(destination.x, origin.y), cc.p(destination.x, destination.y));
|
||||
this.drawLine(cc.p(destination.x, destination.y), cc.p(origin.x, destination.y));
|
||||
this.drawLine(cc.p(origin.x, destination.y), cc.p(origin.x, origin.y));
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a solid rectangle given the origin and destination point measured in points.
|
||||
* @param {cc.Vec2} origin
|
||||
* @param {cc.Vec2} destination
|
||||
* @param {cc.Color} color
|
||||
*/
|
||||
drawSolidRect:function (origin, destination, color) {
|
||||
var vertices = [
|
||||
origin,
|
||||
cc.p(destination.x, origin.y),
|
||||
destination,
|
||||
cc.p(origin.x, destination.y)
|
||||
];
|
||||
|
||||
this.drawSolidPoly(vertices, 4, color);
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a polygon given a pointer to cc.Vec2 coordinates and the number of vertices measured in points.
|
||||
* @override
|
||||
* @param {Array} vertices a pointer to cc.Vec2 coordinates
|
||||
* @param {Number} numOfVertices the number of vertices measured in points
|
||||
* @param {Boolean} closePolygon The polygon can be closed or open
|
||||
* @param {Boolean} [fill=] The polygon can be closed or open and optionally filled with current color
|
||||
*/
|
||||
drawPoly:function (vertices, numOfVertices, closePolygon, fill) {
|
||||
fill = fill || false;
|
||||
|
||||
if (vertices == null)
|
||||
return;
|
||||
|
||||
if (vertices.length < 3)
|
||||
throw new Error("Polygon's point must greater than 2");
|
||||
|
||||
var firstPoint = vertices[0], locContext = this._renderContext.getContext();
|
||||
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
|
||||
locContext.beginPath();
|
||||
locContext.moveTo(firstPoint.x * locScaleX, -firstPoint.y * locScaleY);
|
||||
for (var i = 1, len = vertices.length; i < len; i++)
|
||||
locContext.lineTo(vertices[i].x * locScaleX, -vertices[i].y * locScaleY);
|
||||
|
||||
if (closePolygon)
|
||||
locContext.closePath();
|
||||
|
||||
if (fill)
|
||||
locContext.fill();
|
||||
else
|
||||
locContext.stroke();
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a solid polygon given a pointer to CGPoint coordinates, the number of vertices measured in points, and a color.
|
||||
* @param {Array} polygons
|
||||
* @param {Number} numberOfPoints
|
||||
* @param {cc.Color} color
|
||||
*/
|
||||
drawSolidPoly:function (polygons, numberOfPoints, color) {
|
||||
this.setDrawColor(color.r, color.g, color.b, color.a);
|
||||
this.drawPoly(polygons, numberOfPoints, true, true);
|
||||
},
|
||||
|
||||
/**
|
||||
* 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=]
|
||||
*/
|
||||
drawCircle: function (center, radius, angle, segments, drawLineToCenter) {
|
||||
drawLineToCenter = drawLineToCenter || false;
|
||||
var locContext = this._renderContext.getContext();
|
||||
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
|
||||
locContext.beginPath();
|
||||
var endAngle = angle - Math.PI * 2;
|
||||
locContext.arc(0 | (center.x * locScaleX), 0 | -(center.y * locScaleY), radius * locScaleX, -angle, -endAngle, false);
|
||||
if (drawLineToCenter) {
|
||||
locContext.lineTo(0 | (center.x * locScaleX), 0 | -(center.y * locScaleY));
|
||||
}
|
||||
locContext.stroke();
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a quad bezier path
|
||||
* @override
|
||||
* @param {cc.Vec2} origin
|
||||
* @param {cc.Vec2} control
|
||||
* @param {cc.Vec2} destination
|
||||
* @param {Number} segments
|
||||
*/
|
||||
drawQuadBezier:function (origin, control, destination, segments) {
|
||||
//this is OpenGL Algorithm
|
||||
var vertices = this._cacheArray;
|
||||
vertices.length =0;
|
||||
|
||||
var 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.drawPoly(vertices, segments + 1, false, false);
|
||||
},
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
drawCubicBezier:function (origin, control1, control2, destination, segments) {
|
||||
//this is OpenGL Algorithm
|
||||
var vertices = this._cacheArray;
|
||||
vertices.length =0;
|
||||
|
||||
var 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.drawPoly(vertices, segments + 1, false, false);
|
||||
},
|
||||
|
||||
/**
|
||||
* draw a CatmullRom curve
|
||||
* @override
|
||||
* @param {Array} points
|
||||
* @param {Number} segments
|
||||
*/
|
||||
drawCatmullRom:function (points, segments) {
|
||||
this.drawCardinalSpline(points, 0.5, segments);
|
||||
},
|
||||
|
||||
/**
|
||||
* draw a cardinal spline path
|
||||
* @override
|
||||
* @param {Array} config
|
||||
* @param {Number} tension
|
||||
* @param {Number} segments
|
||||
*/
|
||||
drawCardinalSpline:function (config, tension, segments) {
|
||||
//lazy_init();
|
||||
cc._renderContext.setStrokeStyle("rgba(255,255,255,1)");
|
||||
var points = this._cacheArray;
|
||||
points.length = 0;
|
||||
var p, lt;
|
||||
var 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);
|
||||
points.push(newPos);
|
||||
}
|
||||
this.drawPoly(points, segments + 1, false, false);
|
||||
},
|
||||
|
||||
/**
|
||||
* draw an image
|
||||
* @override
|
||||
* @param {HTMLImageElement|HTMLCanvasElement} image
|
||||
* @param {cc.Vec2} sourcePoint
|
||||
* @param {Size} sourceSize
|
||||
* @param {cc.Vec2} destPoint
|
||||
* @param {Size} destSize
|
||||
*/
|
||||
drawImage:function (image, sourcePoint, sourceSize, destPoint, destSize) {
|
||||
var len = arguments.length;
|
||||
var ctx = this._renderContext.getContext();
|
||||
switch (len) {
|
||||
case 2:
|
||||
var height = image.height;
|
||||
ctx.drawImage(image, sourcePoint.x, -(sourcePoint.y + height));
|
||||
break;
|
||||
case 3:
|
||||
ctx.drawImage(image, sourcePoint.x, -(sourcePoint.y + sourceSize.height), sourceSize.width, sourceSize.height);
|
||||
break;
|
||||
case 5:
|
||||
ctx.drawImage(image, sourcePoint.x, sourcePoint.y, sourceSize.width, sourceSize.height, destPoint.x, -(destPoint.y + destSize.height),
|
||||
destSize.width, destSize.height);
|
||||
break;
|
||||
default:
|
||||
throw new Error("Argument must be non-nil");
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* draw a star
|
||||
* @param {cc.CanvasContextWrapper} ctx canvas context
|
||||
* @param {Number} radius
|
||||
* @param {cc.Color} color
|
||||
*/
|
||||
drawStar:function (ctx, radius, color) {
|
||||
var wrapper = ctx || this._renderContext;
|
||||
var context = wrapper.getContext();
|
||||
radius *= cc.view.getScaleX();
|
||||
var colorStr = "rgba(" + (0 | color.r) + "," + (0 | color.g) + "," + (0 | color.b);
|
||||
wrapper.setFillStyle(colorStr + ",1)");
|
||||
//context.fillStyle = colorStr + ",1)";
|
||||
var subRadius = radius / 10;
|
||||
|
||||
context.beginPath();
|
||||
context.moveTo(-radius, radius);
|
||||
context.lineTo(0, subRadius);
|
||||
context.lineTo(radius, radius);
|
||||
context.lineTo(subRadius, 0);
|
||||
context.lineTo(radius, -radius);
|
||||
context.lineTo(0, -subRadius);
|
||||
context.lineTo(-radius, -radius);
|
||||
context.lineTo(-subRadius, 0);
|
||||
context.lineTo(-radius, radius);
|
||||
context.closePath();
|
||||
context.fill();
|
||||
|
||||
var rg = context.createRadialGradient(0, 0, subRadius, 0, 0, radius);
|
||||
rg.addColorStop(0, colorStr + ", 1)");
|
||||
rg.addColorStop(0.3, colorStr + ", 0.8)");
|
||||
rg.addColorStop(1.0, colorStr + ", 0.0)");
|
||||
wrapper.setFillStyle(rg);
|
||||
//context.fillStyle = g1;
|
||||
context.beginPath();
|
||||
var startAngle_1 = 0;
|
||||
var endAngle_1 = cc.macro.PI2;
|
||||
context.arc(0, 0, radius - subRadius, startAngle_1, endAngle_1, false);
|
||||
context.closePath();
|
||||
context.fill();
|
||||
},
|
||||
|
||||
/**
|
||||
* draw a color ball
|
||||
* @param {cc.CanvasContextWrapper} ctx canvas context
|
||||
* @param {Number} radius
|
||||
* @param {cc.Color} color
|
||||
*/
|
||||
drawColorBall:function (ctx, radius, color) {
|
||||
var wrapper = ctx || this._renderContext;
|
||||
var context = wrapper.getContext();
|
||||
radius *= cc.view.getScaleX();
|
||||
var colorStr = "rgba(" +(0|color.r) + "," + (0|color.g) + "," + (0|color.b);
|
||||
var subRadius = radius / 10;
|
||||
|
||||
var g1 = context.createRadialGradient(0, 0, subRadius, 0, 0, radius);
|
||||
g1.addColorStop(0, colorStr + ", 1)");
|
||||
g1.addColorStop(0.3, colorStr + ", 0.8)");
|
||||
g1.addColorStop(0.6, colorStr + ", 0.4)");
|
||||
g1.addColorStop(1.0, colorStr + ", 0.0)");
|
||||
wrapper.setFillStyle(g1);
|
||||
//context.fillStyle = g1;
|
||||
context.beginPath();
|
||||
var startAngle_1 = 0;
|
||||
var endAngle_1 = cc.macro.PI2;
|
||||
context.arc(0, 0, radius, startAngle_1, endAngle_1, false);
|
||||
context.closePath();
|
||||
context.fill();
|
||||
},
|
||||
|
||||
/**
|
||||
* fill text
|
||||
* @param {String} strText
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
*/
|
||||
fillText:function (strText, x, y) {
|
||||
this._renderContext.getContext().fillText(strText, x, -y);
|
||||
},
|
||||
|
||||
/**
|
||||
* set the drawing color with 4 unsigned bytes
|
||||
* @param {Number} r red value (0 to 255)
|
||||
* @param {Number} g green value (0 to 255)
|
||||
* @param {Number} b blue value (0 to 255)
|
||||
* @param {Number} a Alpha value (0 to 255)
|
||||
*/
|
||||
setDrawColor:function (r, g, b, a) {
|
||||
this._renderContext.setFillStyle("rgba(" + r + "," + g + "," + b + "," + a / 255 + ")");
|
||||
this._renderContext.setStrokeStyle("rgba(" + r + "," + g + "," + b + "," + a / 255 + ")");
|
||||
},
|
||||
|
||||
/**
|
||||
* set the point size in points. Default 1.
|
||||
* @param {Number} pointSize
|
||||
*/
|
||||
setPointSize:function (pointSize) {
|
||||
},
|
||||
|
||||
/**
|
||||
* set the line width. Default 1.
|
||||
* @param {Number} width
|
||||
*/
|
||||
setLineWidth:function (width) {
|
||||
this._renderContext.getContext().lineWidth = width * cc.view.getScaleX();
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = DrawingPrimitiveCanvas;
|
||||
@@ -1,464 +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 macro = cc.macro;
|
||||
|
||||
/**
|
||||
* Canvas of DrawingPrimitive implement version use for WebGlMode
|
||||
* @class
|
||||
* @extends cc._Class
|
||||
*/
|
||||
var DrawingPrimitiveWebGL = cc._Class.extend({
|
||||
|
||||
_initialized:false,
|
||||
_shader: null,
|
||||
_colorLocation: "u_color",
|
||||
_pointSizeLocation: "u_pointSize",
|
||||
_pointSize:-1,
|
||||
/**
|
||||
* contructor of DrawingPrimitiveWebGL
|
||||
* @param ctx rendercontext
|
||||
*/
|
||||
ctor:function (ctx) {
|
||||
if (cc.sys.browserType !== cc.sys.BROWSER_TYPE_WECHAT_GAME && !ctx instanceof WebGLRenderingContext)
|
||||
throw new Error("Can't initialise DrawingPrimitiveWebGL. context need is WebGLRenderingContext");
|
||||
|
||||
this._renderContext = ctx;
|
||||
this._colorArray = new Float32Array([1.0, 1.0, 1.0, 1.0]);
|
||||
},
|
||||
|
||||
lazy_init:function () {
|
||||
var _t = this;
|
||||
if (!_t._initialized) {
|
||||
//
|
||||
// Position and 1 color passed as a uniform (to similate glColor4ub )
|
||||
//
|
||||
_t._shader = cc.shaderCache.programForKey(macro.SHADER_POSITION_UCOLOR);
|
||||
_t._shader._addUniformLocation(_t._colorLocation);
|
||||
_t._shader._addUniformLocation(_t._pointSizeLocation);
|
||||
|
||||
_t._initialized = true;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* initlialize context
|
||||
*/
|
||||
drawInit:function () {
|
||||
this._initialized = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a point given x and y coordinate measured in points
|
||||
* @param {cc.Vec2} point
|
||||
*/
|
||||
drawPoint:function (point) {
|
||||
this.lazy_init();
|
||||
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
glContext.enableVertexAttribArray(macro.VERTEX_ATTRIB_POSITION);
|
||||
this._shader.setUniformLocationWith4fv(this._colorLocation, this._colorArray);
|
||||
this._shader.setUniformLocationWith1f(this._pointSizeLocation, this._pointSize);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
|
||||
glContext.bufferData(glContext.ARRAY_BUFFER, new Float32Array([point.x, point.y]), glContext.STATIC_DRAW);
|
||||
glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
|
||||
|
||||
glContext.drawArrays(glContext.POINTS, 0, 1);
|
||||
glContext.deleteBuffer(pointBuffer);
|
||||
|
||||
cc.incrementGLDraws(1);
|
||||
},
|
||||
|
||||
/**
|
||||
* draws an array of points.
|
||||
* @param {Array} points point of array
|
||||
* @param {Number} numberOfPoints
|
||||
*/
|
||||
drawPoints:function (points, numberOfPoints) {
|
||||
if (!points || points.length === 0)
|
||||
return;
|
||||
|
||||
this.lazy_init();
|
||||
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
glContext.enableVertexAttribArray(macro.VERTEX_ATTRIB_POSITION);
|
||||
this._shader.setUniformLocationWith4fv(this._colorLocation, this._colorArray);
|
||||
this._shader.setUniformLocationWith1f(this._pointSizeLocation, this._pointSize);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
|
||||
glContext.bufferData(glContext.ARRAY_BUFFER, this._pointsToTypeArray(points), glContext.STATIC_DRAW);
|
||||
glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
|
||||
|
||||
glContext.drawArrays(glContext.POINTS, 0, points.length);
|
||||
glContext.deleteBuffer(pointBuffer);
|
||||
|
||||
cc.incrementGLDraws(1);
|
||||
},
|
||||
|
||||
_pointsToTypeArray:function (points) {
|
||||
var typeArr = new Float32Array(points.length * 2);
|
||||
for (var i = 0; i < points.length; i++) {
|
||||
typeArr[i * 2] = points[i].x;
|
||||
typeArr[i * 2 + 1] = points[i].y;
|
||||
}
|
||||
return typeArr;
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a line given the origin and destination point measured in points
|
||||
* @param {cc.Vec2} origin
|
||||
* @param {cc.Vec2} destination
|
||||
*/
|
||||
drawLine:function (origin, destination) {
|
||||
this.lazy_init();
|
||||
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
glContext.enableVertexAttribArray(macro.VERTEX_ATTRIB_POSITION);
|
||||
this._shader.setUniformLocationWith4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
|
||||
glContext.bufferData(glContext.ARRAY_BUFFER, this._pointsToTypeArray([origin, destination]), glContext.STATIC_DRAW);
|
||||
glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
|
||||
|
||||
glContext.drawArrays(glContext.LINES, 0, 2);
|
||||
glContext.deleteBuffer(pointBuffer);
|
||||
|
||||
cc.incrementGLDraws(1);
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a rectangle given the origin and destination point measured in points.
|
||||
* @param {cc.Vec2} origin
|
||||
* @param {cc.Vec2} destination
|
||||
*/
|
||||
drawRect:function (origin, destination) {
|
||||
this.drawLine(cc.p(origin.x, origin.y), cc.p(destination.x, origin.y));
|
||||
this.drawLine(cc.p(destination.x, origin.y), cc.p(destination.x, destination.y));
|
||||
this.drawLine(cc.p(destination.x, destination.y), cc.p(origin.x, destination.y));
|
||||
this.drawLine(cc.p(origin.x, destination.y), cc.p(origin.x, origin.y));
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a solid rectangle given the origin and destination point measured in points.
|
||||
* @param {cc.Vec2} origin
|
||||
* @param {cc.Vec2} destination
|
||||
* @param {cc.Color} color
|
||||
*/
|
||||
drawSolidRect:function (origin, destination, color) {
|
||||
var vertices = [
|
||||
origin,
|
||||
cc.p(destination.x, origin.y),
|
||||
destination,
|
||||
cc.p(origin.x, destination.y)
|
||||
];
|
||||
|
||||
this.drawSolidPoly(vertices, 4, color);
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a polygon given a pointer to cc.Vec2 coordiantes and the number of vertices measured in points.
|
||||
* @param {Array} vertices a pointer to cc.Vec2 coordiantes
|
||||
* @param {Number} numOfVertices the number of vertices measured in points
|
||||
* @param {Boolean} closePolygon The polygon can be closed or open
|
||||
*/
|
||||
drawPoly:function (vertices, numOfVertices, closePolygon) {
|
||||
this.lazy_init();
|
||||
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
glContext.enableVertexAttribArray(macro.VERTEX_ATTRIB_POSITION);
|
||||
this._shader.setUniformLocationWith4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
|
||||
glContext.bufferData(glContext.ARRAY_BUFFER, this._pointsToTypeArray(vertices), glContext.STATIC_DRAW);
|
||||
glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
|
||||
|
||||
if (closePolygon)
|
||||
glContext.drawArrays(glContext.LINE_LOOP, 0, vertices.length);
|
||||
else
|
||||
glContext.drawArrays(glContext.LINE_STRIP, 0, vertices.length);
|
||||
glContext.deleteBuffer(pointBuffer);
|
||||
|
||||
cc.incrementGLDraws(1);
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a solid polygon given a pointer to CGPoint coordiantes, the number of vertices measured in points, and a color.
|
||||
* @param {Array} poli
|
||||
* @param {Number} numberOfPoints
|
||||
* @param {cc.Color} color
|
||||
*/
|
||||
drawSolidPoly:function (poli, numberOfPoints, color) {
|
||||
this.lazy_init();
|
||||
if (color)
|
||||
this.setDrawColor(color.r, color.g, color.b, color.a);
|
||||
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
glContext.enableVertexAttribArray(macro.VERTEX_ATTRIB_POSITION);
|
||||
this._shader.setUniformLocationWith4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
|
||||
glContext.bufferData(glContext.ARRAY_BUFFER, this._pointsToTypeArray(poli), glContext.STATIC_DRAW);
|
||||
glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
|
||||
glContext.drawArrays(glContext.TRIANGLE_FAN, 0, poli.length);
|
||||
glContext.deleteBuffer(pointBuffer);
|
||||
|
||||
cc.incrementGLDraws(1);
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a circle given the center, radius and number of segments.
|
||||
* @param {cc.Vec2} center center of circle
|
||||
* @param {Number} radius
|
||||
* @param {Number} angle angle in radians
|
||||
* @param {Number} segments
|
||||
* @param {Boolean} drawLineToCenter
|
||||
*/
|
||||
drawCircle:function (center, radius, angle, segments, drawLineToCenter) {
|
||||
this.lazy_init();
|
||||
|
||||
var additionalSegment = 1;
|
||||
if (drawLineToCenter)
|
||||
additionalSegment++;
|
||||
|
||||
var coef = 2.0 * Math.PI / segments;
|
||||
|
||||
var vertices = new Float32Array((segments + 2) * 2);
|
||||
if (!vertices)
|
||||
return;
|
||||
|
||||
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[i * 2] = j;
|
||||
vertices[i * 2 + 1] = k;
|
||||
}
|
||||
vertices[(segments + 1) * 2] = center.x;
|
||||
vertices[(segments + 1) * 2 + 1] = center.y;
|
||||
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
glContext.enableVertexAttribArray(macro.VERTEX_ATTRIB_POSITION);
|
||||
this._shader.setUniformLocationWith4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
|
||||
glContext.bufferData(glContext.ARRAY_BUFFER, vertices, glContext.STATIC_DRAW);
|
||||
glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
|
||||
|
||||
glContext.drawArrays(glContext.LINE_STRIP, 0, segments + additionalSegment);
|
||||
glContext.deleteBuffer(pointBuffer);
|
||||
|
||||
cc.incrementGLDraws(1);
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a quad bezier path
|
||||
* @param {cc.Vec2} origin
|
||||
* @param {cc.Vec2} control
|
||||
* @param {cc.Vec2} destination
|
||||
* @param {Number} segments
|
||||
*/
|
||||
drawQuadBezier:function (origin, control, destination, segments) {
|
||||
this.lazy_init();
|
||||
|
||||
var vertices = new Float32Array((segments + 1) * 2);
|
||||
|
||||
var t = 0.0;
|
||||
for (var i = 0; i < segments; i++) {
|
||||
vertices[i * 2] = Math.pow(1 - t, 2) * origin.x + 2.0 * (1 - t) * t * control.x + t * t * destination.x;
|
||||
vertices[i * 2 + 1] = Math.pow(1 - t, 2) * origin.y + 2.0 * (1 - t) * t * control.y + t * t * destination.y;
|
||||
t += 1.0 / segments;
|
||||
}
|
||||
vertices[segments * 2] = destination.x;
|
||||
vertices[segments * 2 + 1] = destination.y;
|
||||
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
glContext.enableVertexAttribArray(macro.VERTEX_ATTRIB_POSITION);
|
||||
this._shader.setUniformLocationWith4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
|
||||
glContext.bufferData(glContext.ARRAY_BUFFER, vertices, glContext.STATIC_DRAW);
|
||||
glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
|
||||
|
||||
glContext.drawArrays(glContext.LINE_STRIP, 0, segments + 1);
|
||||
glContext.deleteBuffer(pointBuffer);
|
||||
|
||||
cc.incrementGLDraws(1);
|
||||
},
|
||||
|
||||
/**
|
||||
* draws a cubic bezier path
|
||||
* @param {cc.Vec2} origin
|
||||
* @param {cc.Vec2} control1
|
||||
* @param {cc.Vec2} control2
|
||||
* @param {cc.Vec2} destination
|
||||
* @param {Number} segments
|
||||
*/
|
||||
drawCubicBezier:function (origin, control1, control2, destination, segments) {
|
||||
this.lazy_init();
|
||||
|
||||
var vertices = new Float32Array((segments + 1) * 2);
|
||||
|
||||
var t = 0;
|
||||
for (var i = 0; i < segments; i++) {
|
||||
vertices[i * 2] = 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;
|
||||
vertices[i * 2 + 1] = 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;
|
||||
t += 1.0 / segments;
|
||||
}
|
||||
vertices[segments * 2] = destination.x;
|
||||
vertices[segments * 2 + 1] = destination.y;
|
||||
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
glContext.enableVertexAttribArray(macro.VERTEX_ATTRIB_POSITION);
|
||||
this._shader.setUniformLocationWith4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
|
||||
glContext.bufferData(glContext.ARRAY_BUFFER, vertices, glContext.STATIC_DRAW);
|
||||
glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
|
||||
glContext.drawArrays(glContext.LINE_STRIP, 0, segments + 1);
|
||||
glContext.deleteBuffer(pointBuffer);
|
||||
|
||||
cc.incrementGLDraws(1);
|
||||
},
|
||||
|
||||
/**
|
||||
* draw a catmull rom line
|
||||
* @param {Array} points
|
||||
* @param {Number} segments
|
||||
*/
|
||||
drawCatmullRom:function (points, segments) {
|
||||
this.drawCardinalSpline(points, 0.5, segments);
|
||||
},
|
||||
|
||||
/**
|
||||
* draw a cardinal spline path
|
||||
* @param {Array} config
|
||||
* @param {Number} tension
|
||||
* @param {Number} segments
|
||||
*/
|
||||
drawCardinalSpline:function (config, tension, segments) {
|
||||
this.lazy_init();
|
||||
|
||||
var vertices = new Float32Array((segments + 1) * 2);
|
||||
var 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;
|
||||
}
|
||||
|
||||
var newPos = cc.cardinalSplineAt(
|
||||
cc.getControlPointAt(config, p - 1),
|
||||
cc.getControlPointAt(config, p),
|
||||
cc.getControlPointAt(config, p + 1),
|
||||
cc.getControlPointAt(config, p + 2),
|
||||
tension, lt);
|
||||
// Interpolate
|
||||
|
||||
vertices[i * 2] = newPos.x;
|
||||
vertices[i * 2 + 1] = newPos.y;
|
||||
}
|
||||
|
||||
var glContext = this._renderContext;
|
||||
this._shader.use();
|
||||
this._shader.setUniformForModelViewAndProjectionMatrixWithMat4();
|
||||
glContext.enableVertexAttribArray(macro.VERTEX_ATTRIB_POSITION);
|
||||
this._shader.setUniformLocationWith4fv(this._colorLocation, this._colorArray);
|
||||
|
||||
var pointBuffer = glContext.createBuffer();
|
||||
glContext.bindBuffer(glContext.ARRAY_BUFFER, pointBuffer);
|
||||
glContext.bufferData(glContext.ARRAY_BUFFER, vertices, glContext.STATIC_DRAW);
|
||||
glContext.vertexAttribPointer(macro.VERTEX_ATTRIB_POSITION, 2, glContext.FLOAT, false, 0, 0);
|
||||
glContext.drawArrays(glContext.LINE_STRIP, 0, segments + 1);
|
||||
glContext.deleteBuffer(pointBuffer);
|
||||
|
||||
cc.incrementGLDraws(1);
|
||||
},
|
||||
|
||||
/**
|
||||
* set the drawing color with 4 unsigned bytes
|
||||
* @param {Number} r red value (0 to 255)
|
||||
* @param {Number} g green value (0 to 255)
|
||||
* @param {Number} b blue value (0 to 255)
|
||||
* @param {Number} a Alpha value (0 to 255)
|
||||
*/
|
||||
setDrawColor:function (r, g, b, a) {
|
||||
this._colorArray[0] = r / 255.0;
|
||||
this._colorArray[1] = g / 255.0;
|
||||
this._colorArray[2] = b / 255.0;
|
||||
this._colorArray[3] = a / 255.0;
|
||||
},
|
||||
|
||||
/**
|
||||
* set the point size in points. Default 1.
|
||||
* @param {Number} pointSize
|
||||
*/
|
||||
setPointSize:function (pointSize) {
|
||||
this._pointSize = pointSize;
|
||||
},
|
||||
|
||||
/**
|
||||
* set the line width. Default 1.
|
||||
* @param {Number} width
|
||||
*/
|
||||
setLineWidth:function (width) {
|
||||
if(this._renderContext.lineWidth)
|
||||
this._renderContext.lineWidth(width);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = DrawingPrimitiveWebGL;
|
||||
@@ -51,11 +51,6 @@ cc.Scene = cc.Class({
|
||||
},
|
||||
|
||||
ctor: function () {
|
||||
var sgNode = this._sgNode = new _ccsg.Scene();
|
||||
if (CC_JSB) {
|
||||
sgNode.retain();
|
||||
}
|
||||
sgNode.setAnchorPoint(0.0, 0.0);
|
||||
this._anchorPoint.x = 0.0;
|
||||
this._anchorPoint.y = 0.0;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
@@ -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";
|
||||
}
|
||||
};
|
||||
@@ -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;
|
||||
};
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* <p>ccsg.Scene is a subclass of ccsg.Node that is used only as an abstract concept.</p>
|
||||
* <p>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.</p>
|
||||
*
|
||||
* <p>For the moment ccsg.Scene has no other logic than that, but in future releases it might have
|
||||
* additional logic.</p>
|
||||
*
|
||||
* <p>It is a good practice to use and ccsg.Scene as the parent of all your nodes.</p>
|
||||
* @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());
|
||||
}
|
||||
});
|
||||
@@ -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');
|
||||
|
||||
/**
|
||||
* <p>_ccsg.Sprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) ) <br/>
|
||||
*
|
||||
* _ccsg.Sprite can be created with an image, or with a sub-rectangle of an image. <br/>
|
||||
*
|
||||
* If the parent or any of its ancestors is a cc.SpriteBatchNode then the following features/limitations are valid <br/>
|
||||
* - Features when the parent is a cc.BatchNode: <br/>
|
||||
* - MUCH faster rendering, specially if the cc.SpriteBatchNode has many children. All the children will be drawn in a single batch. <br/>
|
||||
*
|
||||
* - Limitations <br/>
|
||||
* - Camera is not supported yet (eg: CCOrbitCamera action doesn't work) <br/>
|
||||
* - GridBase actions are not supported (eg: CCLens, CCRipple, CCTwirl) <br/>
|
||||
* - The Alias/Antialias property belongs to CCSpriteBatchNode, so you can't individually set the aliased property. <br/>
|
||||
* - The Blending function property belongs to CCSpriteBatchNode, so you can't individually set the blending function property. <br/>
|
||||
* - Parallax scroller is not supported, but can be simulated with a "proxy" sprite. <br/>
|
||||
*
|
||||
* If the parent is an standard ccsg.Node, then _ccsg.Sprite behaves like any other ccsg.Node: <br/>
|
||||
* - It supports blending functions <br/>
|
||||
* - It supports aliasing / antialiasing <br/>
|
||||
* - But the rendering will be slower: 1 draw per children. <br/>
|
||||
*
|
||||
* The default anchorPoint in _ccsg.Sprite is (0.5, 0.5). </p>
|
||||
* @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.<br/>
|
||||
* 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. <br/>
|
||||
* A cc.SpriteFrame will be fetched from the cc.SpriteFrameCache by name. <br/>
|
||||
* If the cc.SpriteFrame doesn't exist it will raise an exception. <br/>
|
||||
* 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;
|
||||
},
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* set the vertex rect.<br/>
|
||||
* It will be called internally by setTextureRect. <br/>
|
||||
* Useful if you want to create 2x images from SD images in Retina Display. <br/>
|
||||
* Do not call it manually. Use setTextureRect instead. <br/>
|
||||
* (override this method to generate "double scale" sprites)
|
||||
* </p>
|
||||
* @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);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Returns the flag which indicates whether the sprite is flipped horizontally or not. <br/>
|
||||
* <br/>
|
||||
* It only flips the texture of the sprite, and not the texture of the sprite's children. <br/>
|
||||
* Also, flipping the texture doesn't alter the anchorPoint. <br/>
|
||||
* If you want to flip the anchorPoint too, and/or to flip the children too use: <br/>
|
||||
* sprite.setScaleX(sprite.getScaleX() * -1); <p/>
|
||||
* @return {Boolean} true if the sprite is flipped horizontally, false otherwise.
|
||||
*/
|
||||
isFlippedX:function () {
|
||||
return this._flippedX;
|
||||
},
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Return the flag which indicates whether the sprite is flipped vertically or not. <br/>
|
||||
* <br/>
|
||||
* It only flips the texture of the sprite, and not the texture of the sprite's children. <br/>
|
||||
* Also, flipping the texture doesn't alter the anchorPoint. <br/>
|
||||
* If you want to flip the anchorPoint too, and/or to flip the children too use: <br/>
|
||||
* sprite.setScaleY(sprite.getScaleY() * -1); <p/>
|
||||
* @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.<br/>
|
||||
* 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.<br/>
|
||||
* 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;
|
||||
},
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Initializes a sprite with an image filename.<br/>
|
||||
*
|
||||
* This method will find pszFilename from local file system, load its content to CCTexture2D,<br/>
|
||||
* then use CCTexture2D to create a sprite.<br/>
|
||||
* After initialization, the rect used will be the size of the image. The offset will be (0,0).<br/>
|
||||
* Please pass parameters to the constructor to initialize the sprite, do not call this function yourself.
|
||||
* </p>
|
||||
* @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. <br/>
|
||||
* After initialization, the rect used will be the size of the texture, and the offset will be (0,0).<br/>
|
||||
* 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);
|
||||
@@ -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;
|
||||
};
|
||||
@@ -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;
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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"
|
||||
+ "}"
|
||||
};
|
||||
@@ -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.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* A cc.SpriteBatchNode can reference one and only one texture (one image file, one texture atlas).<br/>
|
||||
* Only the cc.Sprites that are contained in that texture can be added to the cc.SpriteBatchNode.<br/>
|
||||
* All cc.Sprites added to a cc.SpriteBatchNode are drawn in one WebGL draw call. <br/>
|
||||
* 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. <br/>
|
||||
* <br/>
|
||||
* Limitations:<br/>
|
||||
* - The only object that is accepted as child (or grandchild, grand-grandchild, etc...) is _ccsg.Sprite or any subclass of _ccsg.Sprite. <br/>
|
||||
* eg: particles, labels and layer can't be added to a cc.SpriteBatchNode. <br/>
|
||||
* - Either all its children are Aliased or Antialiased. It can't be a mix. <br/>
|
||||
* This is because "alias" is a property of the texture, and all the sprites share the same texture. </br>
|
||||
* </p>
|
||||
* @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
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Initializes a cc.SpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children.<br/>
|
||||
* The capacity will be increased in 33% in runtime if it run out of space.<br/>
|
||||
* The file will be loaded using the TextureMgr.<br/>
|
||||
* Please pass parameters to constructor to initialize the sprite batch node, do not call this function yourself.
|
||||
* </p>
|
||||
* @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);
|
||||
},
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Updates a quad at a certain index into the texture atlas. The CCSprite won't be added into the children array. <br/>
|
||||
* 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.<br/>
|
||||
* For example: a tile map (cc.TMXMap) or a label with lots of characters (BitmapFontAtlas)<br/>
|
||||
* </p>
|
||||
* @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);
|
||||
@@ -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'
|
||||
|
||||
+1
-15
@@ -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');
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
****************************************************************************/
|
||||
|
||||
require('./CCParticleAsset');
|
||||
require('./CCSGParticleSystem');
|
||||
require('./CCSGParticleSystemCanvasRenderCmd');
|
||||
require('./CCSGParticleSystemWebGLRenderCmd');
|
||||
// require('./CCSGParticleSystem');
|
||||
// require('./CCSGParticleSystemCanvasRenderCmd');
|
||||
// require('./CCSGParticleSystemWebGLRenderCmd');
|
||||
|
||||
var BlendFactor = cc.BlendFunc.BlendFactor;
|
||||
/**
|
||||
|
||||
@@ -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};
|
||||
};
|
||||
|
||||
/**
|
||||
* <p>CCDrawNode <br/>
|
||||
* Node that draws dots, segments and polygons. <br/>
|
||||
* Faster than the "drawing primitives" since they it draws everything in one single batch.</p>
|
||||
* @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";
|
||||
|
||||
/**
|
||||
* <p>The cc.DrawNodeCanvas's constructor. <br/>
|
||||
* This function will automatically be invoked when you create a node using new construction: "var node = new cc.DrawNodeCanvas()".<br/>
|
||||
* Override it to extend its behavior, remember to call "this._super()" in the extended "ctor" function.</p>
|
||||
*/
|
||||
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);
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -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();
|
||||
};
|
||||
@@ -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();
|
||||
}
|
||||
};
|
||||
@@ -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',
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user