Merge pull request #1565 from pandamicro/jsaction

Pure JS action system working in JSB
This commit is contained in:
Wang Nan
2017-03-29 18:44:21 +08:00
committed by GitHub
17 changed files with 82 additions and 3634 deletions
+1
View File
@@ -1,3 +1,4 @@
require('./CCActionManager.js');
require('./CCAction.js');
require('./CCActionInterval.js');
require('./CCActionInstant.js');
-427
View File
@@ -1,427 +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.
****************************************************************************/
/**
* Base class for Grid actions
* @class
* @extends cc.ActionInterval
* @param {Number} duration
* @param {Size} gridSize
*/
cc.GridAction = cc.ActionInterval.extend(/** @lends cc.GridAction# */{
_gridSize:null,
_gridNodeTarget:null,
/**
* Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
* @param {Number} duration
* @param {Size} gridSize
*/
ctor:function(duration, gridSize){
cc.sys._checkWebGLRenderMode();
cc.ActionInterval.prototype.ctor.call(this);
this._gridSize = cc.size(0,0);
gridSize && this.initWithDuration(duration, gridSize);
},
_cacheTargetAsGridNode:function (target) {
this._gridNodeTarget = target;
},
/**
* to copy object with deep copy.
* returns a clone of action.
*
* @return {cc.Action}
*/
clone:function(){
var action = new cc.GridAction();
var locGridSize = this._gridSize;
action.initWithDuration(this._duration, cc.size(locGridSize.width, locGridSize.height));
return action;
},
/**
* called before the action start. It will also set the target.
*
* @param {_ccsg.Node} target
*/
startWithTarget:function (target) {
cc.ActionInterval.prototype.startWithTarget.call(this, target);
cc.renderer.childrenOrderDirty = true;
this._cacheTargetAsGridNode(target);
var newGrid = this.getGrid();
var targetGrid = this._gridNodeTarget.getGrid();
if (targetGrid && targetGrid.getReuseGrid() > 0) {
var locGridSize = targetGrid.getGridSize();
if (targetGrid.isActive() && (locGridSize.width === this._gridSize.width) && (locGridSize.height === this._gridSize.height))
targetGrid.reuse();
} else {
if (targetGrid && targetGrid.isActive())
targetGrid.setActive(false);
this._gridNodeTarget.setGrid(newGrid);
this._gridNodeTarget.getGrid().setActive(true);
}
},
/**
* Create a cc.ReverseTime action. Opposite with the original motion trajectory.
* @return {cc.ReverseTime}
*/
reverse:function () {
return new cc.ReverseTime(this);
},
/**
* Initializes the action with size and duration.
* @param {Number} duration
* @param {Size} gridSize
* @return {Boolean}
*/
initWithDuration:function (duration, gridSize) {
if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
this._gridSize.width = gridSize.width;
this._gridSize.height = gridSize.height;
return true;
}
return false;
},
/**
* Returns the grid.
* @return {cc.GridBase}
*/
getGrid:function () {
// Abstract class needs implementation
cc.logID(1017);
}
});
/**
* creates the action with size and duration
* @function
* @param {Number} duration
* @param {Size} gridSize
* @return {cc.GridAction}
*/
cc.gridAction = function (duration, gridSize) {
return new cc.GridAction(duration, gridSize);
};
/**
* Please use cc.gridAction instead. <br />
* Creates the action with size and duration.
* @param {Number} duration
* @param {Size} gridSize
* @return {cc.GridAction}
* @static
* @deprecated since v3.0 <br /> Please use cc.gridAction instead.
*/
cc.GridAction.create = cc.gridAction;
/**
* Base class for cc.Grid3D actions. <br/>
* Grid3D actions can modify a non-tiled grid.
* @class
* @extends cc.GridAction
*/
cc.Grid3DAction = cc.GridAction.extend(/** @lends cc.Grid3DAction# */{
/**
* returns the grid
* @return {cc.Grid3D}
*/
getGrid:function () {
return new cc.Grid3D(this._gridSize, undefined, undefined, this._gridNodeTarget.getGridRect());
},
/**
* get rect of the grid
* @return {Rect} rect
*/
getGridRect:function () {
return this._gridNodeTarget.getGridRect();
},
/**
* returns the vertex than belongs to certain position in the grid. <br/>
* It will be deprecated in future, please use getVertex instead.
* @param {cc.Vec2} position
* @return {cc.Vertex3F}
*/
vertex:function (position) {
return this.getVertex(position);
},
/**
* returns the vertex than belongs to certain position in the grid
* @param {cc.Vec2} position
* @return {cc.Vertex3F}
*/
getVertex: function(position){
return this.target.grid.getVertex(position);
},
/**
* returns the non-transformed vertex than belongs to certain position in the grid <br/>
* It will be deprecated in future, please use getVertex instead.
* @param {cc.Vec2} position
* @return {cc.Vertex3F}
*/
originalVertex:function (position) {
return this.getOriginalVertex(position);
},
/**
* returns the non-transformed vertex that belongs to certain position in the grid
* @param {cc.Vec2} position
* @return {cc.Vertex3F}
*/
getOriginalVertex:function (position) {
return this.target.grid.originalVertex(position);
},
/**
* sets a new vertex to a certain position of the grid
* @param {cc.Vec2} position
* @param {cc.Vertex3F} vertex
*/
setVertex:function (position, vertex) {
this.target.grid.setVertex(position, vertex);
}
});
/**
* creates the action with size and duration
* @function
* @param {Number} duration
* @param {Size} gridSize
* @return {cc.Grid3DAction}
*/
cc.grid3DAction = function (duration, gridSize) {
return new cc.Grid3DAction(duration, gridSize);
};
/**
* Please use cc.grid3DAction instead. <br />
* creates the action with size and duration. <br />
* @param {Number} duration
* @param {Size} gridSize
* @return {cc.Grid3DAction}
* @static
* @deprecated since v3.0 <br /> Please use cc.grid3DAction instead.
*/
cc.Grid3DAction.create = cc.grid3DAction;
/**
* Base class for cc.TiledGrid3D actions.
* @class
* @extends cc.GridAction
*/
cc.TiledGrid3DAction = cc.GridAction.extend(/** @lends cc.TiledGrid3DAction# */{
/**
* returns the tile that belongs to a certain position of the grid <br/>
* It will be deprecated in future, please use getTile instead.
* @param {cc.Vec2} position
* @return {cc.Quad3}
*/
tile:function (position) {
return this.getTile(position);
},
/**
* returns the tile that belongs to a certain position of the grid
* @param {cc.Vec2} position
* @return {cc.Quad3}
*/
getTile:function (position) {
return this.target.grid.tile(position);
},
/**
* returns the non-transformed tile that belongs to a certain position of the grid <br/>
* It will be deprecated in future, please use getOriginalTile instead.
* @param {cc.Vec2} position
* @return {cc.Quad3}
*/
originalTile:function (position) {
return this.getOriginalTile(position);
},
/**
* returns the non-transformed tile that belongs to a certain position of the grid
* @param {cc.Vec2} position
* @return {cc.Quad3}
*/
getOriginalTile:function (position) {
return this.target.grid.originalTile(position);
},
/**
* sets a new tile to a certain position of the grid
* @param {cc.Vec2} position
* @param {cc.Quad3} coords
*/
setTile:function (position, coords) {
this.target.grid.setTile(position, coords);
},
/**
* returns the grid
* @return {cc.TiledGrid3D}
*/
getGrid:function () {
return new cc.TiledGrid3D(this._gridSize, undefined, undefined, this._gridNodeTarget.getGridRect());
}
});
/**
* Creates the action with duration and grid size
* @function
* @param {Number} duration
* @param {Size} gridSize
* @return {cc.TiledGrid3DAction}
*/
cc.tiledGrid3DAction = function (duration, gridSize) {
return new cc.TiledGrid3DAction(duration, gridSize);
};
/**
* Please use cc.tiledGrid3DAction instead
* Creates the action with duration and grid size
* @param {Number} duration
* @param {Size} gridSize
* @return {cc.TiledGrid3DAction}
* @static
* @deprecated since v3.0 <br /> Please use cc.tiledGrid3DAction instead.
*/
cc.TiledGrid3DAction.create = cc.tiledGrid3DAction;
/**
* <p>
* cc.StopGrid action. <br/>
* @warning Don't call this action if another grid action is active. <br/>
* Call if you want to remove the the grid effect. Example: <br/>
* cc.sequence(Lens.action(...), cc.stopGrid(...), null); <br/>
* </p>
* @class
* @extends cc.ActionInstant
*/
cc.StopGrid = cc.ActionInstant.extend(/** @lends cc.StopGrid# */{
/**
* called before the action start. It will also set the target.
*
* @param {_ccsg.Node} target
*/
startWithTarget:function (target) {
cc.ActionInstant.prototype.startWithTarget.call(this, target);
cc.renderer.childrenOrderDirty = true;
var grid = this.target.grid;
if (grid && grid.isActive())
grid.setActive(false);
}
});
/**
* Allocates and initializes the action
* @function
* @return {cc.StopGrid}
*/
cc.stopGrid = function () {
return new cc.StopGrid();
};
/**
* Please use cc.stopGrid instead
* Allocates and initializes the action
* @return {cc.StopGrid}
* @static
* @deprecated since v3.0 <br /> Please use cc.stopGrid instead.
*/
cc.StopGrid.create = cc.stopGrid;
/**
* cc.ReuseGrid action
* @class
* @extends cc.ActionInstant
* @param {Number} times
*/
cc.ReuseGrid = cc.ActionInstant.extend(/** @lends cc.ReuseGrid# */{
_times:null,
/**
* Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
* @param {Number} times
*/
ctor: function(times) {
cc.ActionInstant.prototype.ctor.call(this);
times !== undefined && this.initWithTimes(times);
},
/**
* initializes an action with the number of times that the current grid will be reused
* @param {Number} times
* @return {Boolean}
*/
initWithTimes:function (times) {
this._times = times;
return true;
},
/**
* called before the action start. It will also set the target.
*
* @param {_ccsg.Node} target
*/
startWithTarget:function (target) {
cc.ActionInstant.prototype.startWithTarget.call(this, target);
cc.renderer.childrenOrderDirty = true;
if (this.target.grid && this.target.grid.isActive())
this.target.grid.setReuseGrid(this.target.grid.getReuseGrid() + this._times);
}
});
/**
* creates an action with the number of times that the current grid will be reused
* @function
* @param {Number} times
* @return {cc.ReuseGrid}
*/
cc.reuseGrid = function (times) {
return new cc.ReuseGrid(times);
};
/**
* Please use cc.reuseGrid instead
* creates an action with the number of times that the current grid will be reused
* @param {Number} times
* @return {cc.ReuseGrid}
* @static
* @deprecated since v3.0 <br /> Please use cc.reuseGrid instead.
*/
cc.ReuseGrid.create = cc.reuseGrid;
File diff suppressed because it is too large Load Diff
-130
View File
@@ -1,130 +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>
* This action simulates a page turn from the bottom right hand corner of the screen. <br/>
* It's not much use by itself but is used by the PageTurnTransition. <br/>
* <br/>
* Based on an original paper by L Hong et al. <br/>
* http://www.parc.com/publication/1638/turning-pages-of-3d-electronic-books.html
* </p>
* @class
* @extends cc.Grid3DAction
*/
cc.PageTurn3D = cc.Grid3DAction.extend(/** @lends cc.PageTurn3D# */{
getGrid: function(){
var result = new cc.Grid3D(this._gridSize, undefined, undefined, this._gridNodeTarget.getGridRect());
result.setNeedDepthTestForBlit(true);
return result;
},
clone: function(){
var ret = new cc.PageTurn3D();
ret.initWithDuration(this._duration, this._gridSize);
return ret;
},
/**
* Update each tick <br/>
* Time is the percentage of the way through the duration
*/
update:function (time) {
var tt = Math.max(0, time - 0.25);
var deltaAy = (tt * tt * 500);
var ay = -100 - deltaAy;
var deltaTheta = Math.sqrt(time);
var theta = deltaTheta>0.5?Math.PI/2 *deltaTheta : Math.PI/2*(1-deltaTheta);
var rotateByYAxis = (2-time)*Math.PI;
var sinTheta = Math.sin(theta);
var cosTheta = Math.cos(theta);
var locGridSize = this._gridSize;
var locVer = cc.p(0, 0);
for (var i = 0; i <= locGridSize.width; ++i) {
for (var j = 0; j <= locGridSize.height; ++j) {
locVer.x = i;
locVer.y = j;
// Get original vertex
var p = this.getOriginalVertex(locVer);
p.x -= this.getGridRect().x;
var R = Math.sqrt((p.x * p.x) + ((p.y - ay) * (p.y - ay)));
var r = R * sinTheta;
var alpha = Math.asin(p.x / R);
var beta = alpha / sinTheta;
var cosBeta = Math.cos(beta);
// If beta > PI then we've wrapped around the cone
// Reduce the radius to stop these points interfering with others
if (beta <= Math.PI)
p.x = ( r * Math.sin(beta));
else
p.x = 0; //Force X = 0 to stop wrapped points
p.y = ( R + ay - ( r * (1 - cosBeta) * sinTheta));
// We scale z here to avoid the animation being
// too much bigger than the screen due to perspectve transform
p.z = (r * ( 1 - cosBeta ) * cosTheta);// "100" didn't work for
p.x = p.z * Math.sin(rotateByYAxis) + p.x * Math.cos(rotateByYAxis);
p.z = p.z * Math.cos(rotateByYAxis) - p.x * Math.cos(rotateByYAxis);
p.z/= 7;
// Stop z coord from dropping beneath underlying page in a transition
// issue #751
if (p.z < 0.5)
p.z = 0.5;
// Set new coords
p.x+= this.getGridRect().x;
this.setVertex(locVer, p);
}
}
}
});
/**
* create PageTurn3D action
* @function
* @param {Number} duration
* @param {Size} gridSize
* @return {cc.PageTurn3D}
*/
cc.pageTurn3D = function (duration, gridSize) {
return new cc.PageTurn3D(duration, gridSize);
};
/**
* Please use cc.pageTurn3D instead
* create PageTurn3D action
* @param {Number} duration
* @param {Size} gridSize
* @return {cc.PageTurn3D}
* @static
* @deprecated since v3.0 please use cc.pageTurn3D instead.
*/
cc.PageTurn3D.create = cc.pageTurn3D;
File diff suppressed because it is too large Load Diff
+4
View File
@@ -1195,7 +1195,11 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
*/
setActionManager: function (actionManager) {
if (this._actionManager !== actionManager) {
if (this._actionManager) {
this._scheduler.unscheduleUpdate(this._actionManager);
}
this._actionManager = actionManager;
this._scheduler.scheduleUpdate(this._actionManager, cc.Scheduler.PRIORITY_SYSTEM, false);
}
},
+32 -40
View File
@@ -865,7 +865,7 @@ var Node = cc.Class({
sgNode.onEnter = function () {
_ccsg.Node.prototype.onEnter.call(this);
if (this._entity && !this._entity._active) {
cc.director.getActionManager().pauseTarget(this);
cc.director._actionManager && cc.director._actionManager.pauseTarget(this);
cc.eventManager.pauseTarget(this);
}
};
@@ -963,7 +963,10 @@ var Node = cc.Class({
_onPreDestroy () {
var destroyByParent = this._onPreDestroyBase();
cc.director.getActionManager().removeAllActionsFromTarget(this);
// Actions
if (cc.director._actionManager) {
cc.director._actionManager.removeAllActionsFromTarget(this);
}
// Remove Node.currentHovered
if (_currentHovered === this) {
@@ -1008,9 +1011,10 @@ var Node = cc.Class({
},
_onPostActivated (active) {
var actionManager = cc.director._actionManager;
if (active) {
// activate
cc.director.getActionManager().resumeTarget(this);
actionManager && actionManager.resumeTarget(this);
cc.eventManager.resumeTarget(this);
if (this._touchListener) {
var mask = this._touchListener.mask = _searchMaskInParent(this);
@@ -1024,7 +1028,7 @@ var Node = cc.Class({
}
else {
// deactivate
cc.director.getActionManager().pauseTarget(this);
actionManager && actionManager.pauseTarget(this);
cc.eventManager.pauseTarget(this);
}
},
@@ -1056,7 +1060,9 @@ var Node = cc.Class({
if (!this._activeInHierarchy) {
// deactivate ActionManager and EventManager by default
cc.director.getActionManager().pauseTarget(this);
if (cc.director._actionManager) {
cc.director._actionManager.pauseTarget(this);
}
cc.eventManager.pauseTarget(this);
}
@@ -1327,17 +1333,11 @@ var Node = cc.Class({
* node.runAction(action.repeatForever()); // right
*/
runAction (action) {
if (!this.active)
if (!this.active || !cc.director._actionManager)
return;
cc.assertID(action, 1618);
if (!cc.macro.ENABLE_GC_FOR_NATIVE_OBJECTS) {
this._retainAction(action);
}
if (CC_JSB) {
this._sgNode._owner = this;
}
cc.director.getActionManager().addAction(action, this, false);
cc.director._actionManager.addAction(action, this, false);
return action;
},
@@ -1349,7 +1349,9 @@ var Node = cc.Class({
* node.stopAllActions();
*/
stopAllActions () {
cc.director.getActionManager().removeAllActionsFromTarget(this);
if (cc.director._actionManager) {
cc.director._actionManager.removeAllActionsFromTarget(this);
}
},
/**
@@ -1362,7 +1364,9 @@ var Node = cc.Class({
* node.stopAction(action);
*/
stopAction (action) {
cc.director.getActionManager().removeAction(action);
if (cc.director._actionManager) {
cc.director._actionManager.removeAction(action);
}
},
/**
@@ -1378,7 +1382,9 @@ var Node = cc.Class({
cc.logID(1612);
return;
}
cc.director.getActionManager().removeActionByTag(tag, this);
if (cc.director._actionManager) {
cc.director._actionManager.removeActionByTag(tag, this);
}
},
/**
@@ -1396,7 +1402,7 @@ var Node = cc.Class({
cc.logID(1613);
return null;
}
return cc.director.getActionManager().getActionByTag(tag, this);
return cc.director._actionManager ? cc.director._actionManager.getActionByTag(tag, this) : null;
},
/**
@@ -1418,24 +1424,8 @@ var Node = cc.Class({
* cc.log("Running Action Count: " + count);
*/
getNumberOfRunningActions () {
return cc.director.getActionManager().getNumberOfRunningActionsInTarget(this);
},
_retainAction (action) {
if (CC_JSB && action instanceof cc.Action && this._retainedActions.indexOf(action) === -1) {
this._retainedActions.push(action);
action.retain();
}
},
_releaseAllActions () {
if (CC_JSB) {
for (var i = 0; i < this._retainedActions.length; ++i) {
this._retainedActions[i].release();
}
this._retainedActions.length = 0;
}
},
return cc.director._actionManager ? cc.director._actionManager.getNumberOfRunningActionsInTarget(this) : 0;
}
setTag (value) {
this._tag = value;
@@ -2232,7 +2222,7 @@ var Node = cc.Class({
*/
cleanup () {
// actions
cc.director.getActionManager().removeAllActionsFromTarget(this);
cc.director._actionManager && cc.director._actionManager.removeAllActionsFromTarget(this);
// event
cc.eventManager.removeListeners(this);
@@ -2326,12 +2316,13 @@ var Node = cc.Class({
sgNode.setColor(this._color);
// update ActionManager and EventManager because sgNode maybe changed
var actionManager = cc.director._actionManager;
if (this._activeInHierarchy) {
cc.director.getActionManager().resumeTarget(this);
actionManager && actionManager.resumeTarget(this);
cc.eventManager.resumeTarget(this);
}
else {
cc.director.getActionManager().pauseTarget(this);
actionManager && actionManager.pauseTarget(this);
cc.eventManager.pauseTarget(this);
}
},
@@ -2369,12 +2360,13 @@ var Node = cc.Class({
this._onRestoreBase();
var actionManager = cc.director._actionManager;
if (this._activeInHierarchy) {
cc.director.getActionManager().resumeTarget(this);
actionManager && actionManager.resumeTarget(this);
cc.eventManager.resumeTarget(this);
}
else {
cc.director.getActionManager().pauseTarget(this);
actionManager && actionManager.pauseTarget(this);
cc.eventManager.pauseTarget(this);
}
},
+5 -5
View File
@@ -1440,7 +1440,7 @@ _ccsg.Node = cc.Class({
runAction: function (action) {
cc.assertID(action, 1618);
this.actionManager.addAction(action, this, !this._running);
this.actionManager && this.actionManager.addAction(action, this, !this._running);
return action;
},
@@ -1458,7 +1458,7 @@ _ccsg.Node = cc.Class({
* @param {cc.Action} action An action object to be removed.
*/
stopAction: function (action) {
this.actionManager.removeAction(action);
this.actionManager && this.actionManager.removeAction(action);
},
/**
@@ -1471,7 +1471,7 @@ _ccsg.Node = cc.Class({
cc.logID(1612);
return;
}
this.actionManager.removeActionByTag(tag, this);
this.actionManager && this.actionManager.removeActionByTag(tag, this);
},
/**
@@ -1486,7 +1486,7 @@ _ccsg.Node = cc.Class({
cc.logID(1613);
return null;
}
return this.actionManager.getActionByTag(tag, this);
return this.actionManager ? this.actionManager.getActionByTag(tag, this) : null;
},
/** <p>Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays).<br/>
@@ -1497,7 +1497,7 @@ _ccsg.Node = cc.Class({
* @return {Number} The number of actions that are running plus the ones that are schedule to run
*/
getNumberOfRunningActions: function () {
return this.actionManager.getNumberOfRunningActionsInTarget(this);
return this.actionManager ? this.actionManager.getNumberOfRunningActionsInTarget(this) : 0;
},
// _ccsg.Node - Callbacks
+1 -1
View File
@@ -71,7 +71,7 @@ var RendererInSG = cc.Class({
},
onEnable: function () {
if (CC_JSB && cc.director.getActionManager().getNumberOfRunningActionsInTarget(this.node) > 0) {
if (CC_JSB && cc.director._actionManager && cc.director._actionManager.getNumberOfRunningActionsInTarget(this.node) > 0) {
cc.errorID(1629, this.node.name);
cc.errorID(1630);
cc.errorID(1631);
+5 -5
View File
@@ -53,13 +53,13 @@ if (!cc.runtime) {
}
if (!(CC_EDITOR && Editor.isMainProcess)) {
if (!CC_JSB) {
require('./cocos2d/actions');
require('./external/chipmunk/chipmunk.js');
}
require('./cocos2d/actions');
require('./extensions/ccpool/CCNodePool.js');
require('./extensions/ccpool/CCPool.js');
if (!CC_JSB) {
require('./external/chipmunk/chipmunk.js');
}
}
if (!CC_EDITOR || !Editor.isMainProcess) {
-1
View File
@@ -77,7 +77,6 @@ require('./jsb-particle');
require('./jsb-spine');
require('./jsb-enums');
require('./jsb-event');
require('./jsb-action');
require('./jsb-etc');
require('./jsb-audio');
require('./jsb-tiledmap');
-450
View File
@@ -1,450 +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.
****************************************************************************/
var ENABLE_GC_FOR_NATIVE_OBJECTS = cc.macro.ENABLE_GC_FOR_NATIVE_OBJECTS;
// Independent Action from retain/release
var actionArr = [
'ActionEase',
'EaseExponentialIn',
'EaseExponentialOut',
'EaseExponentialInOut',
'EaseSineIn',
'EaseSineOut',
'EaseSineInOut',
'EaseBounce',
'EaseBounceIn',
'EaseBounceOut',
'EaseBounceInOut',
'EaseBackIn',
'EaseBackOut',
'EaseBackInOut',
'EaseRateAction',
'EaseIn',
'EaseElastic',
'EaseElasticIn',
'EaseElasticOut',
'EaseElasticInOut',
'RemoveSelf',
'FlipX',
'FlipY',
'Place',
'CallFunc',
'DelayTime',
'Sequence',
'Spawn',
'Speed',
'Repeat',
'RepeatForever',
'Follow',
'TargetedAction',
'Animate',
'OrbitCamera',
'GridAction',
'ProgressTo',
'ProgressFromTo',
'ActionInterval',
'RotateTo',
'RotateBy',
'MoveBy',
'MoveTo',
'SkewTo',
'SkewBy',
'JumpTo',
'JumpBy',
'ScaleTo',
'ScaleBy',
'Blink',
'FadeTo',
'FadeIn',
'FadeOut',
'TintTo',
'TintBy',
];
function setCtorReplacer (proto) {
var ctor = proto._ctor;
proto._ctor = function (...args) {
ctor.apply(this, args);
this.retain();
this._retained = true;
};
}
function setAliasReplacer (name, type) {
var aliasName = name[0].toLowerCase() + name.substr(1);
cc[aliasName] = function (...args) {
var action = type.create.apply(this, args);
action.retain();
action._retained = true;
return action;
};
}
if (!ENABLE_GC_FOR_NATIVE_OBJECTS) {
for (var i = 0; i < actionArr.length; ++i) {
var name = actionArr[i];
var type = cc[name];
if (!type)
continue;
var proto = type.prototype;
setCtorReplacer(proto);
if (name.indexOf('Ease') === -1) {
setAliasReplacer(name, type);
}
}
}
cc.targetedAction = function (target, action) {
return new cc.TargetedAction(target, action);
};
cc.TargetedAction.prototype._ctor = function(target, action) {
var node = target._sgNode || target;
node._owner = target;
action && this.initWithTarget(node, action);
};
cc.follow = function (followedNode, rect) {
return new cc.Follow(followedNode._sgNode, rect);
};
cc.Follow.prototype.update = function(dt) {
var target = this.getTarget();
if (target._owner) {
target._owner.setPosition(target.getPosition());
}
};
var _FlipX = cc.FlipX;
cc.FlipX = _FlipX.extend({
_flippedX:false,
ctor:function(flip){
_FlipX.prototype.ctor.call(this);
this.initWithFlipX(flip);
},
initWithFlipX:function (flip) {
this._flippedX = !!flip;
return true;
},
update:function (dt) {
var target = this.getTarget();
target.scaleX = Math.abs(target.scaleX) * (this._flippedX ? -1 : 1);
},
reverse:function () {
return new cc.FlipX(!this._flippedX);
},
clone:function(){
return new cc.FlipX(this._flippedX);
}
});
cc.flipX = function (flip) {
return new cc.FlipX(flip);
};
var _FlipY = cc.FlipY;
cc.FlipY = _FlipY.extend({
_flippedY:false,
ctor: function(flip){
_FlipY.prototype.ctor.call(this);
this.initWithFlipY(flip);
},
initWithFlipY:function (flip) {
this._flippedY = !!flip;
return true;
},
update:function (dt) {
var target = this.getTarget();
target.scaleY = Math.abs(target.scaleY) * (this._flippedY ? -1 : 1);
},
reverse:function () {
return new cc.FlipY(!this._flippedY);
},
clone:function(){
return new cc.FlipY(this._flippedY);
}
});
cc.flipY = function (flip) {
return new cc.FlipY(flip);
};
function setRendererVisibility (sgNode, toggleVisible, visible) {
if (!sgNode) { return; }
var _renderComps = sgNode._owner.getComponentsInChildren(cc._SGComponent);
for (var i = 0; i < _renderComps.length; ++i) {
var render = _renderComps[i];
render.enabled = toggleVisible ? !render.enabled : visible;
}
}
cc.Show.prototype.update = function (dt) {
setRendererVisibility(this.getTarget(), false, true);
};
cc.Hide.prototype.update = function (dt) {
setRendererVisibility(this.getTarget(), false, false);
};
cc.ToggleVisibility.prototype.update = function (dt) {
setRendererVisibility(this.getTarget(), true);
};
// Special call func
cc.callFunc = function (selector, selectorTarget, data) {
var callback = function (sender, data) {
if (sender) {
sender = sender._owner || sender;
}
selector.call(this, sender, data);
};
var action = cc.CallFunc.create(callback, selectorTarget, data);
if (!ENABLE_GC_FOR_NATIVE_OBJECTS) {
action.retain();
action._retained = true;
}
return action;
};
cc.CallFunc.prototype._ctor = function (selector, selectorTarget, data) {
if(selector !== undefined){
var callback = function (sender, data) {
if (sender) {
sender = sender._owner || sender;
}
selector.call(this, sender, data);
};
if(selectorTarget === undefined)
this.initWithFunction(callback);
else this.initWithFunction(callback, selectorTarget, data);
}
if (!ENABLE_GC_FOR_NATIVE_OBJECTS) {
this.retain();
this._retained = true;
}
};
function setChainFuncReplacer (proto, name) {
var oldFunc = proto[name];
proto[name] = function (...args) {
if (this._retained) {
this.release();
this._retained = false;
}
var newAction = oldFunc.apply(this, args);
newAction.retain();
newAction._retained = true;
return newAction;
};
}
if (!ENABLE_GC_FOR_NATIVE_OBJECTS) {
setChainFuncReplacer(cc.ActionInterval.prototype, 'repeat');
setChainFuncReplacer(cc.ActionInterval.prototype, 'repeatForever');
setChainFuncReplacer(cc.ActionInterval.prototype, 'easing');
var jsbRunAction = cc.Node.prototype.runAction;
cc.Node.prototype.runAction = function (action) {
jsbRunAction.call(this, action);
if (action._retained) {
action.release();
action._retained = false;
}
return action;
};
}
function getSGTarget (target) {
if (target instanceof cc.Component) {
target = target.node._sgNode;
}
else if (target instanceof cc.Node) {
target = target._sgNode;
}
else if (!(target instanceof _ccsg.Node)) {
target = null;
}
return target;
}
var jsbAddAction = cc.ActionManager.prototype.addAction;
cc.ActionManager.prototype.addAction = function (action, target, paused) {
target = getSGTarget(target);
if (target) {
jsbAddAction.call(this, action, target, paused);
if (!ENABLE_GC_FOR_NATIVE_OBJECTS && action._retained) {
action.release();
action._retained = false;
}
}
};
function actionMgrFuncReplacer (funcName, targetPos) {
var proto = cc.ActionManager.prototype;
var oldFunc = proto[funcName];
proto[funcName] = function (...args) {
for (var i = 0; i < args.length; i++) {
if (i === targetPos)
args[i] = getSGTarget(args[i]);
}
if (!args[targetPos]) {
return;
}
else {
return oldFunc.apply(this, args);
}
};
}
var targetRelatedFuncs = [
['removeAllActionsFromTarget', 0],
['removeActionByTag', 1],
['getActionByTag', 1],
['getNumberOfRunningActionsInTarget', 0],
['pauseTarget', 0],
['resumeTarget', 0]
];
for (var i = 0; i < targetRelatedFuncs.length; ++i) {
actionMgrFuncReplacer.apply(null, targetRelatedFuncs[i]);
}
cc.ActionManager.prototype.resumeTargets = function (targetsToResume) {
if (!targetsToResume)
return;
for (var i = 0; i< targetsToResume.length; i++) {
if (targetsToResume[i])
this.resumeTarget(targetsToResume[i]);
}
};
cc.ActionManager.prototype.pauseTargets = function (targetsToPause) {
if (!targetsToPause)
return;
for (var i = 0; i< targetsToPause.length; i++) {
if (targetsToPause[i])
this.pauseTarget(targetsToPause[i]);
}
};
function syncPositionUpdate (dt) {
this._jsbUpdate(dt);
var target = this.getTarget();
if (target._owner) {
target._owner.x = target.getPositionX();
target._owner.y = target.getPositionY();
}
}
function syncRotationUpdate (dt) {
this._jsbUpdate(dt);
var target = this.getTarget();
if (target._owner) {
target._owner.rotationX = target.getRotationX();
target._owner.rotationY = target.getRotationY();
}
}
function syncScaleUpdate (dt) {
this._jsbUpdate(dt);
var target = this.getTarget();
if (target._owner) {
target._owner.scaleX = target.getScaleX();
target._owner.scaleY = target.getScaleY();
}
}
function syncRemoveSelfUpdate (dt) {
this._jsbUpdate(dt);
var target = this.getTarget();
if (target._owner) {
target._owner.removeFromParent();
}
}
function syncSkewUpdate (dt) {
this._jsbUpdate(dt);
var target = this.getTarget();
if (target._owner) {
target._owner.skewX = target.getSkewX();
target._owner.skewY = target.getSkewY();
}
}
function syncOpacityUpdate (dt) {
this._jsbUpdate(dt);
var target = this.getTarget();
if (target._owner) {
target._owner.opacity = target.getOpacity();
}
}
function syncColorUpdate (dt) {
this._jsbUpdate(dt);
var target = this.getTarget();
if (target._owner) {
target._owner.color = target.getColor();
}
}
// Sub classes must be registered before their super class.
// Otherwise, JSB there will be internal Error: "too much recursion".
var actionUpdate = {
'MoveBy': syncPositionUpdate,
'JumpBy': syncPositionUpdate,
'Place': syncPositionUpdate,
'CardinalSplineTo': syncPositionUpdate,
'RotateTo': syncRotationUpdate,
'RotateBy': syncRotationUpdate,
'ScaleTo': syncScaleUpdate,
'RemoveSelf': syncRemoveSelfUpdate,
'SkewTo': syncSkewUpdate,
'Blink': syncOpacityUpdate,
'FadeIn': syncOpacityUpdate,
'FadeOut': syncOpacityUpdate,
'FadeTo': syncOpacityUpdate,
'TintTo': syncColorUpdate,
'TintBy': syncColorUpdate,
'BezierBy': syncPositionUpdate
};
for (var key in actionUpdate) {
var action = cc[key];
action.prototype._jsbUpdate = action.prototype.update;
action.prototype.update = actionUpdate[key];
}
+29 -5
View File
@@ -42,10 +42,19 @@ cc.js.mixin(cc.director, {
this._compScheduler = new ComponentScheduler();
this._nodeActivator = new NodeActivator();
var scheduler = this.getScheduler();
// ActionManager
if (cc.ActionManager) {
this._actionManager = new cc.ActionManager();
scheduler.scheduleUpdate(this._actionManager, cc.Scheduler.PRIORITY_SYSTEM, false);
} else {
this._actionManager = null;
}
// Animation manager
if (cc.AnimationManager) {
this._animationManager = new cc.AnimationManager();
this.getScheduler().scheduleUpdate(this._animationManager, cc.Scheduler.PRIORITY_SYSTEM, false);
scheduler.scheduleUpdate(this._animationManager, cc.Scheduler.PRIORITY_SYSTEM, false);
}
else {
this._animationManager = null;
@@ -54,7 +63,7 @@ cc.js.mixin(cc.director, {
// collider manager
if (cc.CollisionManager) {
this._collisionManager = new cc.CollisionManager();
this.getScheduler().scheduleUpdate(this._collisionManager, cc.Scheduler.PRIORITY_SYSTEM, false);
scheduler.scheduleUpdate(this._collisionManager, cc.Scheduler.PRIORITY_SYSTEM, false);
}
else {
this._collisionManager = null;
@@ -89,9 +98,8 @@ cc.js.mixin(cc.director, {
cc.eventManager.setEnabled(true);
// Action manager
var actionManager = this.getActionManager();
if (actionManager) {
this.getScheduler().scheduleUpdate(actionManager, cc.Scheduler.PRIORITY_SYSTEM, false);
if (this._actionManager) {
this.getScheduler().scheduleUpdate(this._actionManager, cc.Scheduler.PRIORITY_SYSTEM, false);
}
// Animation manager
@@ -112,6 +120,20 @@ cc.js.mixin(cc.director, {
this.startAnimation();
},
getActionManager: function () {
return this._actionManager;
},
setActionManager: function (actionManager) {
if (this._actionManager !== actionManager) {
if (this._actionManager) {
this._scheduler.unscheduleUpdate(this._actionManager);
}
this._actionManager = actionManager;
this._scheduler.scheduleUpdate(this._actionManager, cc.Scheduler.PRIORITY_SYSTEM, false);
}
},
/**
* Returns the cc.AnimationManager associated with this director.
* @method getAnimationManager
@@ -436,6 +458,8 @@ cc.js.mixin(cc.director, {
},
});
cc.defineGetterSetter(cc.director, "actionManager", cc.director.getActionManager, cc.director.setActionManager);
cc.EventTarget.call(cc.director);
cc.js.addon(cc.director, cc.EventTarget.prototype);
-8
View File
@@ -25,14 +25,6 @@
'use strict';
cc.ProgressTimer.Type = cc.Enum({
/**
* Radial Counter-Clockwise
*/
RADIAL: 0,
BAR: 1
});
//FIXME: should delete this line after implementing the VideoPlayer on Mac and Windows
if (cc.sys.os === cc.sys.OS_OSX || cc.sys.os === cc.sys.OS_WINDOWS) {
cc.VideoPlayer = {};
-3
View File
@@ -207,9 +207,6 @@ window._ccsg = {
window.__errorHandler = function (filename, lineno, message) {
};
// rename cc.Class to cc._Class
cc._Class = cc.Class;
// fix cc.formatStr (#2630)
cc.formatStr = cc.js.formatStr;
+5 -2
View File
@@ -73,7 +73,11 @@ require('./cocos2d/core/platform/CCMacro');
require('./cocos2d/core/load-pipeline');
require('./cocos2d/core/textures');
if (!CC_JSB) {
if (CC_JSB) {
// rename cc.Class to cc._Class
cc._Class = cc.Class;
}
else {
require('./cocos2d/kazmath');
require('./cocos2d/core/CCDirector');
require('./cocos2d/core/CCDirectorWebGL');
@@ -83,7 +87,6 @@ if (!CC_JSB) {
require('./cocos2d/core/platform/CCSAXParser');
require('./cocos2d/core/platform/CCView');
require('./cocos2d/core/platform/CCScreen');
require('./cocos2d/core/CCActionManager');
require('./cocos2d/core/CCScheduler');
require('./cocos2d/core/event-manager');
require('./cocos2d/core/renderer');