diff --git a/DebugInfos.js b/DebugInfos.js
index 6820a0532f..267af7738e 100644
--- a/DebugInfos.js
+++ b/DebugInfos.js
@@ -65,6 +65,7 @@ if (CC_DEBUG) {
"1404": "cc.spriteFrameCache is removed, please use cc.loader to load and cache sprite frames of atlas format.",
"1405": "The '%s' will be removed in v2.0, please use '%s' instead. \uD83D\uDE30",
"1406": "'%s.%s' is removed", // removed
+ "1407": "cc.pool is being removed from v2.0, you are getting cc.js.Pool instead",
//Scheduler: 1500
"1500": "cc.Scheduler#schedule: Callback already scheduled. Updating interval from:%s to %s", //scheduleCallbackForTarget
"1501": "cc.Scheduler#scheduleCallbackForTarget(): callback_fn should be non-null.", //scheduleCallbackForTarget_2
@@ -121,10 +122,10 @@ if (CC_DEBUG) {
"1702": "cocos2d: Could not initialize cc.AtlasNode. Invalid Texture.", //_initWithTexture
"1703": "The new text must be String", //TextAtlas.text
//_checkEventListenerAvailable: 1800
- "1800": "cc._EventListenerKeyboard.checkAvailable(): Invalid EventListenerKeyboard!", //keyboard
- "1801": "cc._EventListenerTouchOneByOne.checkAvailable(): Invalid EventListenerTouchOneByOne!", //touchOneByOne
- "1802": "cc._EventListenerTouchAllAtOnce.checkAvailable(): Invalid EventListenerTouchAllAtOnce!", //touchAllAtOnce
- "1803": "cc._EventListenerAcceleration.checkAvailable(): _onAccelerationEvent must be non-nil", //acceleration
+ "1800": "Keyboard EventListener checkAvailable(): Invalid EventListenerKeyboard!", //keyboard
+ "1801": "TouchOneByOne EventListener checkAvailable(): Invalid EventListenerTouchOneByOne!", //touchOneByOne
+ "1802": "TouchAllAtOnce EventListener checkAvailable(): Invalid EventListenerTouchAllAtOnce!", //touchAllAtOnce
+ "1803": "Acceleration EventListener checkAvailable(): _onAccelerationEvent must be non-nil", //acceleration
//EventListener: 1900
"1900": "Invalid parameter.", //create
//__getListenerID: 2000
diff --git a/cocos2d/actions/CCAction.js b/cocos2d/actions/CCAction.js
index 57e49ea6b7..dc037306ed 100644
--- a/cocos2d/actions/CCAction.js
+++ b/cocos2d/actions/CCAction.js
@@ -24,6 +24,8 @@
THE SOFTWARE.
****************************************************************************/
+require('../core/platform/CCClass');
+
/**
* @module cc
*/
@@ -33,7 +35,8 @@
* !#zh Action 类是所有动作类型的基类。
* @class Action
*/
-cc.Action = cc._Class.extend({
+cc.Action = cc.Class({
+ name: 'cc.Action',
//**************Public Functions***********
@@ -185,12 +188,12 @@ cc.Action.TAG_INVALID = -1;
* @class FiniteTimeAction
* @extends Action
*/
-cc.FiniteTimeAction = cc.Action.extend({
- //! duration in seconds
- _duration:0,
+cc.FiniteTimeAction = cc.Class({
+ name: 'cc.FiniteTimeAction',
+ extends: cc.Action,
ctor:function () {
- cc.Action.prototype.ctor.call(this);
+ //! duration in seconds
this._duration = 0;
},
@@ -259,12 +262,11 @@ cc.FiniteTimeAction = cc.Action.extend({
* @param {ActionInterval} action
* @param {Number} speed
*/
-cc.Speed = cc.Action.extend({
- _speed:0.0,
- _innerAction:null,
+cc.Speed = cc.Class({
+ name: 'cc.Speed',
+ extends: cc.Action,
ctor:function (action, speed) {
- cc.Action.prototype.ctor.call(this);
this._speed = 0;
this._innerAction = null;
@@ -410,22 +412,9 @@ cc.speed = function (action, speed) {
* @class
* @extends Action
*/
-cc.Follow = cc.Action.extend({
- // node to follow
- _followedNode:null,
- // whether camera should be limited to certain area
- _boundarySet:false,
- // if screen size is bigger than the boundary - update not needed
- _boundaryFullyCovered:false,
- // fast access to the screen dimensions
- _halfScreenSize:null,
- _fullScreenSize:null,
- _worldRect:null,
-
- leftBoundary:0.0,
- rightBoundary:0.0,
- topBoundary:0.0,
- bottomBoundary:0.0,
+cc.Follow = cc.Class({
+ name: 'cc.Follow',
+ extends: cc.Action,
/*
* Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
@@ -435,11 +424,13 @@ cc.Follow = cc.Action.extend({
* @param {Rect} rect
*/
ctor:function (followedNode, rect) {
- cc.Action.prototype.ctor.call(this);
+ // node to follow
this._followedNode = null;
+ // whether camera should be limited to certain area
this._boundarySet = false;
-
+ // if screen size is bigger than the boundary - update not needed
this._boundaryFullyCovered = false;
+ // fast access to the screen dimensions
this._halfScreenSize = null;
this._fullScreenSize = null;
diff --git a/cocos2d/actions/CCActionCatmullRom.js b/cocos2d/actions/CCActionCatmullRom.js
index 63fb9b1dfe..6d02ed9c2e 100644
--- a/cocos2d/actions/CCActionCatmullRom.js
+++ b/cocos2d/actions/CCActionCatmullRom.js
@@ -50,7 +50,7 @@
* @param {Number} t
* @return {Vec2}
*/
-cc.cardinalSplineAt = function (p0, p1, p2, p3, tension, t) {
+function cardinalSplineAt (p0, p1, p2, p3, tension, t) {
var t2 = t * t;
var t3 = t2 * t;
@@ -76,7 +76,7 @@ cc.cardinalSplineAt = function (p0, p1, p2, p3, tension, t) {
* @param {Number} pos
* @return {Array}
*/
-cc.getControlPointAt = function (controlPoints, pos) {
+function getControlPointAt (controlPoints, pos) {
var p = Math.min(controlPoints.length - 1, Math.max(pos, 0));
return controlPoints[p];
};
@@ -112,18 +112,17 @@ function cloneControlPoints (controlPoints) {
* //create a cc.CardinalSplineTo
* var action1 = cc.cardinalSplineTo(3, array, 0);
*/
-cc.CardinalSplineTo = cc.ActionInterval.extend({
- /* Array of control points */
- _points:null,
- _deltaT:0,
- _tension:0,
- _previousPosition:null,
- _accumulatedDiff:null,
+cc.CardinalSplineTo = cc.Class({
+ name: 'cc.CardinalSplineTo',
+ extends: cc.ActionInterval,
ctor: function (duration, points, tension) {
- cc.ActionInterval.prototype.ctor.call(this);
-
+ /* Array of control points */
this._points = [];
+ this._deltaT = 0;
+ this._tension = 0;
+ this._previousPosition = null;
+ this._accumulatedDiff = null;
tension !== undefined && this.initWithDuration(duration, points, tension);
},
@@ -170,11 +169,11 @@ cc.CardinalSplineTo = cc.ActionInterval.extend({
lt = (dt - locDT * p) / locDT;
}
- var newPos = cc.cardinalSplineAt(
- cc.getControlPointAt(ps, p - 1),
- cc.getControlPointAt(ps, p - 0),
- cc.getControlPointAt(ps, p + 1),
- cc.getControlPointAt(ps, p + 2),
+ var newPos = cardinalSplineAt(
+ getControlPointAt(ps, p - 1),
+ getControlPointAt(ps, p - 0),
+ getControlPointAt(ps, p + 1),
+ getControlPointAt(ps, p + 2),
this._tension, lt);
if (cc.macro.ENABLE_STACKABLE_ACTIONS) {
@@ -260,13 +259,12 @@ cc.cardinalSplineTo = function (duration, points, tension) {
* //create a cc.CardinalSplineBy
* var action1 = cc.cardinalSplineBy(3, array, 0);
*/
-cc.CardinalSplineBy = cc.CardinalSplineTo.extend({
- _startPosition:null,
+cc.CardinalSplineBy = cc.Class({
+ name: 'cc.CardinalSplineBy',
+ extends: cc.CardinalSplineTo,
ctor:function (duration, points, tension) {
- cc.CardinalSplineTo.prototype.ctor.call(this);
this._startPosition = cc.p(0, 0);
-
tension !== undefined && this.initWithDuration(duration, points, tension);
},
@@ -362,7 +360,9 @@ cc.cardinalSplineBy = function (duration, points, tension) {
* @example
* var action1 = cc.catmullRomTo(3, array);
*/
-cc.CatmullRomTo = cc.CardinalSplineTo.extend({
+cc.CatmullRomTo = cc.Class({
+ name: 'cc.CatmullRomTo',
+ extends: cc.CardinalSplineTo,
ctor: function(dt, points) {
points && this.initWithDuration(dt, points);
@@ -409,10 +409,11 @@ cc.catmullRomTo = function (dt, points) {
* @example
* var action1 = cc.catmullRomBy(3, array);
*/
-cc.CatmullRomBy = cc.CardinalSplineBy.extend({
+cc.CatmullRomBy = cc.Class({
+ name: 'cc.CatmullRomBy',
+ extends: cc.CardinalSplineBy,
ctor: function(dt, points) {
- cc.CardinalSplineBy.prototype.ctor.call(this);
points && this.initWithDuration(dt, points);
},
diff --git a/cocos2d/actions/CCActionEase.js b/cocos2d/actions/CCActionEase.js
index 809b55085d..81399ac8d1 100644
--- a/cocos2d/actions/CCActionEase.js
+++ b/cocos2d/actions/CCActionEase.js
@@ -28,169 +28,6 @@
* @module cc
*/
-/**
- * !#en Base class for Easing actions.
- * !#zh 所有缓动动作基类,用于修饰 ActionInterval。
- * @class ActionEase
- * @extends ActionInterval
- * @param {ActionInterval} action
- */
-cc.ActionEase = cc.ActionInterval.extend({
- _inner:null,
-
- ctor: function (action) {
- cc.ActionInterval.prototype.ctor.call(this);
- action && this.initWithAction(action);
- },
-
- /**
- * initializes the action
- *
- * @param {ActionInterval} action
- * @return {Boolean}
- */
- initWithAction:function (action) {
- if(!action)
- throw new Error(cc._getError(1023));
-
- if (this.initWithDuration(action.getDuration())) {
- this._inner = action;
- return true;
- }
- return false;
- },
-
- clone:function(){
- var action = new cc.ActionEase();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._inner.startWithTarget(this.target);
- },
-
- stop:function () {
- this._inner.stop();
- cc.ActionInterval.prototype.stop.call(this);
- },
-
- update:function (dt) {
- this._inner.update(dt);
- },
-
- reverse:function () {
- return new cc.ActionEase(this._inner.reverse());
- },
-
- /**
- * Get inner Action.
- *
- * @return {ActionInterval}
- */
- getInnerAction:function(){
- return this._inner;
- }
-});
-
-cc.actionEase = function (action) {
- return new cc.ActionEase(action);
-};
-
-/**
- * !#en Base class for Easing actions with rate parameters
- * !#zh 拥有速率属性的缓动动作基类。
- * @class EaseRateAction
- * @extends ActionEase
- * @param {ActionInterval} action
- * @param {Number} rate
- */
-cc.EaseRateAction = cc.ActionEase.extend({
- _rate:0,
-
- ctor: function(action, rate){
- cc.ActionEase.prototype.ctor.call(this);
-
- rate !== undefined && this.initWithAction(action, rate);
- },
-
- /**
- * set rate value for the actions
- * @param {Number} rate
- */
- setRate:function (rate) {
- this._rate = rate;
- },
-
- /** get rate value for the actions
- * @return {Number}
- */
- getRate:function () {
- return this._rate;
- },
-
- /**
- * Initializes the action with the inner action and the rate parameter
- * @param {ActionInterval} action
- * @param {Number} rate
- * @return {Boolean}
- */
- initWithAction:function (action, rate) {
- if (cc.ActionEase.prototype.initWithAction.call(this, action)) {
- this._rate = rate;
- return true;
- }
- return false;
- },
-
- clone:function(){
- var action = new cc.EaseRateAction();
- action.initWithAction(this._inner.clone(), this._rate);
- return action;
- },
-
- reverse:function () {
- return new cc.EaseRateAction(this._inner.reverse(), 1 / this._rate);
- }
-});
-
-cc.easeRateAction = function (action, rate) {
- return new cc.EaseRateAction(action, rate);
-};
-
-/**
- * @module cc
- */
-
-/*
- * cc.EaseIn action with a rate. From slow to fast.
- *
- * @class EaseIn
- * @extends EaseRateAction
- *
- * @deprecated since v3.0 please use action.easing(cc.easeIn(3));
- *
- * @example
- * action.easing(cc.easeIn(3.0));
- */
-cc.EaseIn = cc.EaseRateAction.extend({
-
- update:function (dt) {
- this._inner.update(Math.pow(dt, this._rate));
- },
-
- reverse:function () {
- return new cc.EaseIn(this._inner.reverse(), 1 / this._rate);
- },
-
- clone:function(){
- var action = new cc.EaseIn();
- action.initWithAction(this._inner.clone(), this._rate);
- return action;
- }
-});
-
/**
* !#en
* Creates the action easing object with the rate parameter.
@@ -214,33 +51,6 @@ cc.easeIn = function (rate) {
};
};
-/*
- * cc.EaseOut action with a rate. From fast to slow.
- *
- * @class EaseOut
- * @extends EaseRateAction
- *
- * @deprecated since v3.0 please use action.easing(cc.easeOut(3))
- *
- * @example
- * action.easing(cc.easeOut(3.0));
- */
-cc.EaseOut = cc.EaseRateAction.extend({
- update:function (dt) {
- this._inner.update(Math.pow(dt, 1 / this._rate));
- },
-
- reverse:function () {
- return new cc.EaseOut(this._inner.reverse(), 1 / this._rate);
- },
-
- clone:function(){
- var action = new cc.EaseOut();
- action.initWithAction(this._inner.clone(),this._rate);
- return action;
- }
-});
-
/**
* !#en
* Creates the action easing object with the rate parameter.
@@ -264,37 +74,6 @@ cc.easeOut = function (rate) {
};
};
-/*
- * cc.EaseInOut action with a rate.
- * Slow to fast then to slow.
- * @class EaseInOut
- * @extends EaseRateAction
- *
- * @deprecated since v3.0 please use action.easing(cc.easeInOut(3.0))
- *
- * @example
- * action.easing(cc.easeInOut(3.0));
- */
-cc.EaseInOut = cc.EaseRateAction.extend({
- update:function (dt) {
- dt *= 2;
- if (dt < 1)
- this._inner.update(0.5 * Math.pow(dt, this._rate));
- else
- this._inner.update(1.0 - 0.5 * Math.pow(2 - dt, this._rate));
- },
-
- clone:function(){
- var action = new cc.EaseInOut();
- action.initWithAction(this._inner.clone(), this._rate);
- return action;
- },
-
- reverse:function () {
- return new cc.EaseInOut(this._inner.reverse(), this._rate);
- }
-});
-
/**
* !#en
* Creates the action easing object with the rate parameter.
@@ -323,43 +102,6 @@ cc.easeInOut = function (rate) {
};
};
-/*
- * cc.Ease Exponential In. Slow to Fast.
- * Reference easeInExpo:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseExponentialIn
- * @extends ActionEase
- *
- * @deprecated since v3.0 please action.easing(cc.easeExponentialIn())
- *
- * @example
- * action.easing(cc.easeExponentialIn());
- */
-cc.EaseExponentialIn = cc.ActionEase.extend({
- update:function (dt) {
- this._inner.update(dt === 0 ? 0 : Math.pow(2, 10 * (dt - 1)));
- },
-
- reverse:function () {
- return new cc.EaseExponentialOut(this._inner.reverse());
- },
-
- clone:function(){
- var action = new cc.EaseExponentialIn();
- action.initWithAction(this._inner.clone());
- return action;
- }
-});
-
-cc._easeExponentialInObj = {
- easing: function(dt){
- return dt === 0 ? 0 : Math.pow(2, 10 * (dt - 1));
- },
- reverse: function(){
- return cc._easeExponentialOutObj;
- }
-};
-
/**
* !#en
* Creates the action easing object with the rate parameter.
@@ -374,46 +116,17 @@ cc._easeExponentialInObj = {
* @example
* action.easing(cc.easeExponentialIn());
*/
-cc.easeExponentialIn = function(){
- return cc._easeExponentialInObj;
-};
-
-/*
- * Ease Exponential Out.
- * Reference easeOutExpo:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseExponentialOut
- * @extends ActionEase
- *
- * @deprecated since v3.0 please use action.easing(cc.easeExponentialOut())
- *
- * @example
- * action.easing(cc.easeExponentialOut());
- */
-cc.EaseExponentialOut = cc.ActionEase.extend({
- update:function (dt) {
- this._inner.update(dt === 1 ? 1 : (-(Math.pow(2, -10 * dt)) + 1));
- },
-
- reverse:function () {
- return new cc.EaseExponentialIn(this._inner.reverse());
- },
-
- clone:function(){
- var action = new cc.EaseExponentialOut();
- action.initWithAction(this._inner.clone());
- return action;
- }
-});
-
-cc._easeExponentialOutObj = {
+var _easeExponentialInObj = {
easing: function(dt){
- return dt === 1 ? 1 : (-(Math.pow(2, -10 * dt)) + 1);
+ return dt === 0 ? 0 : Math.pow(2, 10 * (dt - 1));
},
reverse: function(){
- return cc._easeExponentialInObj;
+ return _easeExponentialOutObj;
}
};
+cc.easeExponentialIn = function(){
+ return _easeExponentialInObj;
+};
/**
* !#en
@@ -429,61 +142,17 @@ cc._easeExponentialOutObj = {
* @example
* action.easing(cc.easeExponentialOut());
*/
-cc.easeExponentialOut = function(){
- return cc._easeExponentialOutObj;
-};
-
-/*
- * Ease Exponential InOut.
- * Reference easeInOutExpo:
- * http://www.zhihu.com/question/21981571/answer/19925418
- *
- * @class EaseExponentialInOut
- * @extends ActionEase
- *
- * @deprecated since v3.0 please use action.easing(cc.easeExponentialInOut)
- *
- * @example
- * action.easing(cc.easeExponentialInOut());
- */
-cc.EaseExponentialInOut = cc.ActionEase.extend({
- update:function (dt) {
- if( dt !== 1 && dt !== 0) {
- dt *= 2;
- if (dt < 1)
- dt = 0.5 * Math.pow(2, 10 * (dt - 1));
- else
- dt = 0.5 * (-Math.pow(2, -10 * (dt - 1)) + 2);
- }
- this._inner.update(dt);
- },
-
- reverse:function () {
- return new cc.EaseExponentialInOut(this._inner.reverse());
- },
-
- clone:function(){
- var action = new cc.EaseExponentialInOut();
- action.initWithAction(this._inner.clone());
- return action;
- }
-});
-
-cc._easeExponentialInOutObj = {
+var _easeExponentialOutObj = {
easing: function(dt){
- if( dt !== 1 && dt !== 0) {
- dt *= 2;
- if (dt < 1)
- return 0.5 * Math.pow(2, 10 * (dt - 1));
- else
- return 0.5 * (-Math.pow(2, -10 * (dt - 1)) + 2);
- }
- return dt;
+ return dt === 1 ? 1 : (-(Math.pow(2, -10 * dt)) + 1);
},
reverse: function(){
- return cc._easeExponentialInOutObj;
+ return _easeExponentialInObj;
}
};
+cc.easeExponentialOut = function(){
+ return _easeExponentialOutObj;
+};
/**
* !#en
@@ -499,47 +168,25 @@ cc._easeExponentialInOutObj = {
* @example
* action.easing(cc.easeExponentialInOut());
*/
-cc.easeExponentialInOut = function(){
- return cc._easeExponentialInOutObj;
-};
-
-/*
- * Ease Sine In.
- * Reference easeInSine:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseSineIn
- * @extends ActionEase
- *
- * @deprecated since v3.0 please use action.easing(cc.easeSineIn())
- *
- * @example
- * action.easing(cc.easeSineIn());
- */
-cc.EaseSineIn = cc.ActionEase.extend({
- update:function (dt) {
- dt = dt===0 || dt===1 ? dt : -1 * Math.cos(dt * Math.PI / 2) + 1;
- this._inner.update(dt);
- },
-
- reverse:function () {
- return new cc.EaseSineOut(this._inner.reverse());
- },
-
- clone:function(){
- var action = new cc.EaseSineIn();
- action.initWithAction(this._inner.clone());
- return action;
- }
-});
-
-cc._easeSineInObj = {
+var _easeExponentialInOutObj = {
easing: function(dt){
- return (dt===0 || dt===1) ? dt : -1 * Math.cos(dt * Math.PI / 2) + 1;
+ if( dt !== 1 && dt !== 0) {
+ dt *= 2;
+ if (dt < 1)
+ return 0.5 * Math.pow(2, 10 * (dt - 1));
+ else
+ return 0.5 * (-Math.pow(2, -10 * (dt - 1)) + 2);
+ }
+ return dt;
},
reverse: function(){
- return cc._easeSineOutObj;
+ return _easeExponentialInOutObj;
}
};
+cc.easeExponentialInOut = function(){
+ return _easeExponentialInOutObj;
+};
+
/**
* !#en
* Creates an EaseSineIn action.
@@ -554,47 +201,17 @@ cc._easeSineInObj = {
* @example
* action.easing(cc.easeSineIn());
*/
-cc.easeSineIn = function(){
- return cc._easeSineInObj;
-};
-
-/*
- * Ease Sine Out.
- * Reference easeOutSine:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseSineOut
- * @extends ActionEase
- *
- * @deprecated since v3.0 please use action.easing(cc.easeSineOut())
- *
- * @example
- * action.easing(cc.easeSineOut());
- */
-cc.EaseSineOut = cc.ActionEase.extend({
- update:function (dt) {
- dt = dt===0 || dt===1 ? dt : Math.sin(dt * Math.PI / 2);
- this._inner.update(dt);
- },
-
- reverse:function () {
- return new cc.EaseSineIn(this._inner.reverse());
- },
-
- clone:function(){
- var action = new cc.EaseSineOut();
- action.initWithAction(this._inner.clone());
- return action;
- }
-});
-
-cc._easeSineOutObj = {
+var _easeSineInObj = {
easing: function(dt){
- return (dt===0 || dt===1) ? dt : Math.sin(dt * Math.PI / 2);
+ return (dt===0 || dt===1) ? dt : -1 * Math.cos(dt * Math.PI / 2) + 1;
},
reverse: function(){
- return cc._easeSineInObj;
+ return _easeSineOutObj;
}
};
+cc.easeSineIn = function(){
+ return _easeSineInObj;
+};
/**
* !#en
@@ -610,47 +227,17 @@ cc._easeSineOutObj = {
* @example
* action.easing(cc.easeSineOut());
*/
-cc.easeSineOut = function(){
- return cc._easeSineOutObj;
-};
-
-/*
- * Ease Sine InOut.
- * Reference easeInOutSine:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class cc.EaseSineInOut
- * @extends ActionEase
- *
- * @deprecated since v3.0 please use action.easing(cc.easeSineInOut())
- *
- * @example
- * action.easing(cc.easeSineInOut());
- */
-cc.EaseSineInOut = cc.ActionEase.extend({
- update:function (dt) {
- dt = dt===0 || dt===1 ? dt : -0.5 * (Math.cos(Math.PI * dt) - 1);
- this._inner.update(dt);
- },
-
- clone:function(){
- var action = new cc.EaseSineInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse:function () {
- return new cc.EaseSineInOut(this._inner.reverse());
- }
-});
-
-cc._easeSineInOutObj = {
+var _easeSineOutObj = {
easing: function(dt){
- return (dt === 0 || dt === 1) ? dt : -0.5 * (Math.cos(Math.PI * dt) - 1);
+ return (dt===0 || dt===1) ? dt : Math.sin(dt * Math.PI / 2);
},
reverse: function(){
- return cc._easeSineInOutObj;
+ return _easeSineInObj;
}
};
+cc.easeSineOut = function(){
+ return _easeSineOutObj;
+};
/**
* !#en
@@ -666,121 +253,22 @@ cc._easeSineInOutObj = {
* @example
* action.easing(cc.easeSineInOut());
*/
-cc.easeSineInOut = function(){
- return cc._easeSineInOutObj;
-};
-
-/**
- * !#en Ease Elastic abstract class.
- * !#zh 弹性缓动动作基类。
- * @class EaseElastic
- * @extends ActionEase
- * @param {ActionInterval} action
- * @param {Number} period
- */
-cc.EaseElastic = cc.ActionEase.extend({
- _period: 0.3,
-
- ctor:function(action, period){
- cc.ActionEase.prototype.ctor.call(this);
-
- action && this.initWithAction(action, period);
+var _easeSineInOutObj = {
+ easing: function(dt){
+ return (dt === 0 || dt === 1) ? dt : -0.5 * (Math.cos(Math.PI * dt) - 1);
},
-
- /**
- * get period of the wave in radians. default is 0.3
- * @return {Number}
- */
- getPeriod:function () {
- return this._period;
- },
-
- /**
- * set period of the wave in radians.
- * @param {Number} period
- */
- setPeriod:function (period) {
- this._period = period;
- },
-
- /**
- * Initializes the action with the inner action and the period in radians (default is 0.3)
- * @param {ActionInterval} action
- * @param {Number} [period=0.3]
- * @return {Boolean}
- */
- initWithAction:function (action, period) {
- cc.ActionEase.prototype.initWithAction.call(this, action);
- this._period = (period == null) ? 0.3 : period;
- return true;
- },
-
- reverse:function () {
- cc.logID(1009);
- return null;
- },
-
- clone:function(){
- var action = new cc.EaseElastic();
- action.initWithAction(this._inner.clone(), this._period);
- return action;
+ reverse: function(){
+ return _easeSineInOutObj;
}
-});
+};
+cc.easeSineInOut = function(){
+ return _easeSineInOutObj;
+};
/**
* @module cc
*/
-/*
- * Ease Elastic In action.
- * Reference easeInElastic:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
- * @class EaseElasticIn
- * @extends EaseElastic
- *
- * @deprecated since v3.0 please use action.easing(cc.easeElasticIn())
- *
- * @example
- * action.easing(cc.easeElasticIn(period));
- */
-cc.EaseElasticIn = cc.EaseElastic.extend({
- update:function (dt) {
- var newT = 0;
- if (dt === 0 || dt === 1) {
- newT = dt;
- } else {
- var s = this._period / 4;
- dt = dt - 1;
- newT = -Math.pow(2, 10 * dt) * Math.sin((dt - s) * Math.PI * 2 / this._period);
- }
- this._inner.update(newT);
- },
-
- reverse:function () {
- return new cc.EaseElasticOut(this._inner.reverse(), this._period);
- },
-
- clone:function(){
- var action = new cc.EaseElasticIn();
- action.initWithAction(this._inner.clone(), this._period);
- return action;
- }
-});
-
-//default ease elastic in object (period = 0.3)
-cc._easeElasticInObj = {
- easing:function(dt){
- if (dt === 0 || dt === 1)
- return dt;
- dt = dt - 1;
- return -Math.pow(2, 10 * dt) * Math.sin((dt - (0.3 / 4)) * Math.PI * 2 / 0.3);
- },
- reverse:function(){
- return cc._easeElasticOutObj;
- }
-};
-
/**
* !#en
* Creates the action easing obejct with the period in radians (default is 0.3).
@@ -797,6 +285,18 @@ cc._easeElasticInObj = {
* // example
* action.easing(cc.easeElasticIn(3.0));
*/
+//default ease elastic in object (period = 0.3)
+var _easeElasticInObj = {
+ easing:function(dt){
+ if (dt === 0 || dt === 1)
+ return dt;
+ dt = dt - 1;
+ return -Math.pow(2, 10 * dt) * Math.sin((dt - (0.3 / 4)) * Math.PI * 2 / 0.3);
+ },
+ reverse:function(){
+ return _easeElasticOutObj;
+ }
+ };
cc.easeElasticIn = function (period) {
if(period && period !== 0.3){
return {
@@ -812,55 +312,9 @@ cc.easeElasticIn = function (period) {
}
};
}
- return cc._easeElasticInObj;
+ return _easeElasticInObj;
};
-/*
- * Ease Elastic Out action.
- * Reference easeOutElastic:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
- * @class EaseElasticOut
- * @extends EaseElastic
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeElasticOut(period))
- *
- * @example
- * action.easing(cc.easeElasticOut(period));
- */
-cc.EaseElasticOut = cc.EaseElastic.extend({
- update:function (dt) {
- var newT = 0;
- if (dt === 0 || dt === 1) {
- newT = dt;
- } else {
- var s = this._period / 4;
- newT = Math.pow(2, -10 * dt) * Math.sin((dt - s) * Math.PI * 2 / this._period) + 1;
- }
-
- this._inner.update(newT);
- },
-
- reverse:function () {
- return new cc.EaseElasticIn(this._inner.reverse(), this._period);
- },
-
- clone:function(){
- var action = new cc.EaseElasticOut();
- action.initWithAction(this._inner.clone(), this._period);
- return action;
- }
-});
-
-//default ease elastic out object (period = 0.3)
-cc._easeElasticOutObj = {
- easing: function (dt) {
- return (dt === 0 || dt === 1) ? dt : Math.pow(2, -10 * dt) * Math.sin((dt - (0.3 / 4)) * Math.PI * 2 / 0.3) + 1;
- },
- reverse:function(){
- return cc._easeElasticInObj;
- }
-};
/**
* !#en
* Creates the action easing object with the period in radians (default is 0.3).
@@ -877,6 +331,15 @@ cc._easeElasticOutObj = {
* // example
* action.easing(cc.easeElasticOut(3.0));
*/
+//default ease elastic out object (period = 0.3)
+var _easeElasticOutObj = {
+ easing: function (dt) {
+ return (dt === 0 || dt === 1) ? dt : Math.pow(2, -10 * dt) * Math.sin((dt - (0.3 / 4)) * Math.PI * 2 / 0.3) + 1;
+ },
+ reverse:function(){
+ return _easeElasticInObj;
+ }
+};
cc.easeElasticOut = function (period) {
if(period && period !== 0.3){
return {
@@ -889,54 +352,9 @@ cc.easeElasticOut = function (period) {
}
};
}
- return cc._easeElasticOutObj;
+ return _easeElasticOutObj;
};
-/*
- * Ease Elastic InOut action.
- * Reference easeInOutElastic:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
- * @class EaseElasticInOut
- * @extends EaseElastic
- *
- * @deprecated since v3.0 please use action.easing(cc.easeElasticInOut())
- *
- * @example
- * action.easing(cc.easeElasticInOut(period));
- */
-cc.EaseElasticInOut = cc.EaseElastic.extend({
- update:function (dt) {
- var newT = 0;
- var locPeriod = this._period;
- if (dt === 0 || dt === 1) {
- newT = dt;
- } else {
- dt = dt * 2;
- if (!locPeriod)
- locPeriod = this._period = 0.3 * 1.5;
-
- var s = locPeriod / 4;
- dt = dt - 1;
- if (dt < 0)
- newT = -0.5 * Math.pow(2, 10 * dt) * Math.sin((dt - s) * Math.PI * 2 / locPeriod);
- else
- newT = Math.pow(2, -10 * dt) * Math.sin((dt - s) * Math.PI * 2 / locPeriod) * 0.5 + 1;
- }
- this._inner.update(newT);
- },
-
- reverse:function () {
- return new cc.EaseElasticInOut(this._inner.reverse(), this._period);
- },
-
- clone:function(){
- var action = new cc.EaseElasticInOut();
- action.initWithAction(this._inner.clone(), this._period);
- return action;
- }
-});
-
/**
* !#en
* Creates the action easing object with the period in radians (default is 0.3).
@@ -981,77 +399,11 @@ cc.easeElasticInOut = function (period) {
};
};
-/**
- * !#en cc.EaseBounce abstract class.
- * !#zh 反弹缓动动作基类。
- * @class EaseBounce
- * @extends ActionEase
- */
-cc.EaseBounce = cc.ActionEase.extend({
- /**
- * @param {Number} time1
- * @return {Number}
- */
- bounceTime:function (time1) {
- if (time1 < 1 / 2.75) {
- return 7.5625 * time1 * time1;
- } else if (time1 < 2 / 2.75) {
- time1 -= 1.5 / 2.75;
- return 7.5625 * time1 * time1 + 0.75;
- } else if (time1 < 2.5 / 2.75) {
- time1 -= 2.25 / 2.75;
- return 7.5625 * time1 * time1 + 0.9375;
- }
-
- time1 -= 2.625 / 2.75;
- return 7.5625 * time1 * time1 + 0.984375;
- },
-
- clone:function(){
- var action = new cc.EaseBounce();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse:function () {
- return new cc.EaseBounce(this._inner.reverse());
- }
-});
-
/**
* @module cc
*/
-/*
- * cc.EaseBounceIn action.
- * Eased bounce effect at the beginning.
- * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
- * @class EaseBounceIn
- * @extends EaseBounce
- *
- * @deprecated since v3.0 please use action.easing(cc.easeBounceIn())
- *
- * @example
- * action.easing(cc.easeBounceIn());
- */
-cc.EaseBounceIn = cc.EaseBounce.extend({
- update:function (dt) {
- var newT = 1 - this.bounceTime(1 - dt);
- this._inner.update(newT);
- },
-
- reverse:function () {
- return new cc.EaseBounceOut(this._inner.reverse());
- },
-
- clone:function(){
- var action = new cc.EaseBounceIn();
- action.initWithAction(this._inner.clone());
- return action;
- }
-});
-
-cc._bounceTime = function (time1) {
+function _bounceTime (time1) {
if (time1 < 1 / 2.75) {
return 7.5625 * time1 * time1;
} else if (time1 < 2 / 2.75) {
@@ -1066,12 +418,12 @@ cc._bounceTime = function (time1) {
return 7.5625 * time1 * time1 + 0.984375;
};
-cc._easeBounceInObj = {
+var _easeBounceInObj = {
easing: function(dt){
- return 1 - cc._bounceTime(1 - dt);
+ return 1 - _bounceTime(1 - dt);
},
reverse: function(){
- return cc._easeBounceOutObj;
+ return _easeBounceOutObj;
}
};
@@ -1089,45 +441,7 @@ cc._easeBounceInObj = {
* action.easing(cc.easeBounceIn());
*/
cc.easeBounceIn = function(){
- return cc._easeBounceInObj;
-};
-
-/*
- * cc.EaseBounceOut action.
- * Eased bounce effect at the ending.
- * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
- * @class EaseBounceOut
- * @extends EaseBounce
- *
- * @deprecated since v3.0 please use action.easing(cc.easeBounceOut())
- *
- * @example
- * action.easing(cc.easeBounceOut());
- */
-cc.EaseBounceOut = cc.EaseBounce.extend({
- update:function (dt) {
- var newT = this.bounceTime(dt);
- this._inner.update(newT);
- },
-
- reverse:function () {
- return new cc.EaseBounceIn(this._inner.reverse());
- },
-
- clone:function(){
- var action = new cc.EaseBounceOut();
- action.initWithAction(this._inner.clone());
- return action;
- }
-});
-
-cc._easeBounceOutObj = {
- easing: function(dt){
- return cc._bounceTime(dt);
- },
- reverse:function () {
- return cc._easeBounceInObj;
- }
+ return _easeBounceInObj;
};
/**
@@ -1143,60 +457,17 @@ cc._easeBounceOutObj = {
* // example
* action.easing(cc.easeBounceOut());
*/
-cc.easeBounceOut = function(){
- return cc._easeBounceOutObj;
-};
-
-/*
- * cc.EaseBounceInOut action.
- * Eased bounce effect at the begining and ending.
- * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
- * @class EaseBounceInOut
- * @extends EaseBounce
- *
- * @deprecated since v3.0
Please use acton.easing(cc.easeBounceInOut())
- *
- * @example
- * action.easing(cc.easeBounceInOut());
- */
-cc.EaseBounceInOut = cc.EaseBounce.extend({
- update:function (dt) {
- var newT = 0;
- if (dt < 0.5) {
- dt = dt * 2;
- newT = (1 - this.bounceTime(1 - dt)) * 0.5;
- } else {
- newT = this.bounceTime(dt * 2 - 1) * 0.5 + 0.5;
- }
- this._inner.update(newT);
+var _easeBounceOutObj = {
+ easing: function(dt){
+ return _bounceTime(dt);
},
-
- clone:function(){
- var action = new cc.EaseBounceInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
reverse:function () {
- return new cc.EaseBounceInOut(this._inner.reverse());
- }
-});
-
-cc._easeBounceInOutObj = {
- easing: function (time1) {
- var newT;
- if (time1 < 0.5) {
- time1 = time1 * 2;
- newT = (1 - cc._bounceTime(1 - time1)) * 0.5;
- } else {
- newT = cc._bounceTime(time1 * 2 - 1) * 0.5 + 0.5;
- }
- return newT;
- },
- reverse: function(){
- return cc._easeBounceInOutObj;
+ return _easeBounceInObj;
}
};
+cc.easeBounceOut = function(){
+ return _easeBounceOutObj;
+};
/**
* !#en
@@ -1211,49 +482,24 @@ cc._easeBounceInOutObj = {
* // example
* action.easing(cc.easeBounceInOut());
*/
-cc.easeBounceInOut = function(){
- return cc._easeBounceInOutObj;
-};
-
-/*
- * cc.EaseBackIn action.
- * In the opposite direction to move slowly, and then accelerated to the right direction.
- * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
- * @class EaseBackIn
- * @extends ActionEase
- *
- * @deprecated since v3.0 please use action.easing(cc.easeBackIn())
- *
- * @example
- * action.easing(cc.easeBackIn());
- */
-cc.EaseBackIn = cc.ActionEase.extend({
- update:function (dt) {
- var overshoot = 1.70158;
- dt = dt===0 || dt===1 ? dt : dt * dt * ((overshoot + 1) * dt - overshoot);
- this._inner.update(dt);
- },
-
- reverse:function () {
- return new cc.EaseBackOut(this._inner.reverse());
- },
-
- clone:function(){
- var action = new cc.EaseBackIn();
- action.initWithAction(this._inner.clone());
- return action;
- }
-});
-
-cc._easeBackInObj = {
+var _easeBounceInOutObj = {
easing: function (time1) {
- var overshoot = 1.70158;
- return (time1===0 || time1===1) ? time1 : time1 * time1 * ((overshoot + 1) * time1 - overshoot);
+ var newT;
+ if (time1 < 0.5) {
+ time1 = time1 * 2;
+ newT = (1 - _bounceTime(1 - time1)) * 0.5;
+ } else {
+ newT = _bounceTime(time1 * 2 - 1) * 0.5 + 0.5;
+ }
+ return newT;
},
reverse: function(){
- return cc._easeBackOutObj;
+ return _easeBounceInOutObj;
}
};
+cc.easeBounceInOut = function(){
+ return _easeBounceInOutObj;
+};
/**
* !#en
@@ -1268,50 +514,18 @@ cc._easeBackInObj = {
* // example
* action.easing(cc.easeBackIn());
*/
-cc.easeBackIn = function(){
- return cc._easeBackInObj;
-};
-
-/*
- * cc.EaseBackOut action.
- * Fast moving more than the finish, and then slowly back to the finish.
- * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
- * @class EaseBackOut
- * @extends ActionEase
- *
- * @deprecated since v3.0 please use action.easing(cc.easeBackOut());
- *
- * @example
- * action.easing(cc.easeBackOut());
- */
-cc.EaseBackOut = cc.ActionEase.extend({
- update:function (dt) {
- var overshoot = 1.70158;
- dt = dt - 1;
- this._inner.update(dt * dt * ((overshoot + 1) * dt + overshoot) + 1);
- },
-
- reverse:function () {
- return new cc.EaseBackIn(this._inner.reverse());
- },
-
- clone:function(){
- var action = new cc.EaseBackOut();
- action.initWithAction(this._inner.clone());
- return action;
- }
-});
-
-cc._easeBackOutObj = {
+var _easeBackInObj = {
easing: function (time1) {
var overshoot = 1.70158;
- time1 = time1 - 1;
- return time1 * time1 * ((overshoot + 1) * time1 + overshoot) + 1;
+ return (time1===0 || time1===1) ? time1 : time1 * time1 * ((overshoot + 1) * time1 - overshoot);
},
reverse: function(){
- return cc._easeBackInObj;
+ return _easeBackOutObj;
}
};
+cc.easeBackIn = function(){
+ return _easeBackInObj;
+};
/**
* !#en
@@ -1326,60 +540,19 @@ cc._easeBackOutObj = {
* // example
* action.easing(cc.easeBackOut());
*/
-cc.easeBackOut = function(){
- return cc._easeBackOutObj;
-};
-
-/*
- * cc.EaseBackInOut action.
- * Begining of cc.EaseBackIn. Ending of cc.EaseBackOut.
- * @warning This action doesn't use a bijective function. Actions like Sequence might have an unexpected result when used with this action.
- * @class EaseBackInOut
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeBackInOut())
- *
- * @example
- * action.easing(cc.easeBackInOut());
- */
-cc.EaseBackInOut = cc.ActionEase.extend({
- update:function (dt) {
- var overshoot = 1.70158 * 1.525;
- dt = dt * 2;
- if (dt < 1) {
- this._inner.update((dt * dt * ((overshoot + 1) * dt - overshoot)) / 2);
- } else {
- dt = dt - 2;
- this._inner.update((dt * dt * ((overshoot + 1) * dt + overshoot)) / 2 + 1);
- }
- },
-
- clone:function(){
- var action = new cc.EaseBackInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse:function () {
- return new cc.EaseBackInOut(this._inner.reverse());
- }
-});
-
-cc._easeBackInOutObj = {
+var _easeBackOutObj = {
easing: function (time1) {
- var overshoot = 1.70158 * 1.525;
- time1 = time1 * 2;
- if (time1 < 1) {
- return (time1 * time1 * ((overshoot + 1) * time1 - overshoot)) / 2;
- } else {
- time1 = time1 - 2;
- return (time1 * time1 * ((overshoot + 1) * time1 + overshoot)) / 2 + 1;
- }
+ var overshoot = 1.70158;
+ time1 = time1 - 1;
+ return time1 * time1 * ((overshoot + 1) * time1 + overshoot) + 1;
},
reverse: function(){
- return cc._easeBackInOutObj;
+ return _easeBackInObj;
}
};
+cc.easeBackOut = function(){
+ return _easeBackOutObj;
+};
/**
* !#en
@@ -1393,75 +566,24 @@ cc._easeBackInOutObj = {
* // example
* action.easing(cc.easeBackInOut());
*/
-cc.easeBackInOut = function(){
- return cc._easeBackInOutObj;
-};
-
-/*
- * cc.EaseBezierAction action.
- * Manually set a 4 order Bessel curve.
- * According to the set point, calculate the trajectory.
- * @class EaseBezierAction
- * @extends ActionEase
- * @param {Action} action
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeBezierAction())
- *
- * @example
- * action.easing(cc.easeBezierAction(0.5, 0.5, 1.0, 1.0));
- */
-cc.EaseBezierAction = cc.ActionEase.extend({
-
- _p0: null,
- _p1: null,
- _p2: null,
- _p3: null,
-
- /**
- * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
- * Initialization requires the application of Bessel curve of action.
- * @param {Action} action
- */
- ctor: function(action){
- cc.ActionEase.prototype.ctor.call(this, action);
+var _easeBackInOutObj = {
+ easing: function (time1) {
+ var overshoot = 1.70158 * 1.525;
+ time1 = time1 * 2;
+ if (time1 < 1) {
+ return (time1 * time1 * ((overshoot + 1) * time1 - overshoot)) / 2;
+ } else {
+ time1 = time1 - 2;
+ return (time1 * time1 * ((overshoot + 1) * time1 + overshoot)) / 2 + 1;
+ }
},
-
- _updateTime: function(a, b, c, d, t){
- return (Math.pow(1-t,3) * a + 3*t*(Math.pow(1-t,2))*b + 3*Math.pow(t,2)*(1-t)*c + Math.pow(t,3)*d );
- },
-
- update: function(dt){
- var t = this._updateTime(this._p0, this._p1, this._p2, this._p3, dt);
- this._inner.update(t);
- },
-
- clone: function(){
- var action = new cc.EaseBezierAction();
- action.initWithAction(this._inner.clone());
- action.setBezierParamer(this._p0, this._p1, this._p2, this._p3);
- return action;
- },
-
reverse: function(){
- var action = new cc.EaseBezierAction(this._inner.reverse());
- action.setBezierParamer(this._p3, this._p2, this._p1, this._p0);
- return action;
- },
-
- /**
- * Set of 4 reference point
- * @param p0
- * @param p1
- * @param p2
- * @param p3
- */
- setBezierParamer: function(p0, p1, p2, p3){
- this._p0 = p0 || 0;
- this._p1 = p1 || 0;
- this._p2 = p2 || 0;
- this._p3 = p3 || 0;
+ return _easeBackInOutObj;
}
-});
+};
+cc.easeBackInOut = function(){
+ return _easeBackInOutObj;
+};
/**
* !#en
@@ -1481,58 +603,17 @@ cc.EaseBezierAction = cc.ActionEase.extend({
* // example
* action.easing(cc.easeBezierAction(0.5, 0.5, 1.0, 1.0));
*/
-cc.easeBezierAction = function(p0, p1, p2, p3){
+cc.easeBezierAction = function(a, b, c, d){
return {
- easing: function(time){
- return cc.EaseBezierAction.prototype._updateTime(p0, p1, p2, p3, time);
+ easing: function(t){
+ return (Math.pow(1-t,3) * a + 3*t*(Math.pow(1-t,2))*b + 3*Math.pow(t,2)*(1-t)*c + Math.pow(t,3)*d);
},
reverse: function(){
- return cc.easeBezierAction(p3, p2, p1, p0);
+ return cc.easeBezierAction(d, c, b, a);
}
};
};
-/*
- * cc.EaseQuadraticActionIn action.
- * Reference easeInQuad:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseQuadraticActionIn
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeQuadraticAction())
- *
- * @example
- * action.easing(cc.easeQuadraticActionIn());
- */
-cc.EaseQuadraticActionIn = cc.ActionEase.extend({
-
- _updateTime: function(time){
- return Math.pow(time, 2);
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseQuadraticActionIn();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseQuadraticActionIn(this._inner.reverse());
- }
-
-});
-
-cc._easeQuadraticActionIn = {
- easing: cc.EaseQuadraticActionIn.prototype._updateTime,
- reverse: function(){
- return cc._easeQuadraticActionIn;
- }
-};
-
/**
* !#en
* Creates the action easing object.
@@ -1548,49 +629,18 @@ cc._easeQuadraticActionIn = {
* //example
* action.easing(cc.easeQuadraticActionIn());
*/
+var _easeQuadraticActionIn = {
+ easing: function(time){
+ return Math.pow(time, 2);
+ },
+ reverse: function(){
+ return _easeQuadraticActionIn;
+ }
+};
cc.easeQuadraticActionIn = function(){
- return cc._easeQuadraticActionIn;
+ return _easeQuadraticActionIn;
};
-/*
- * cc.EaseQuadraticActionIn action.
- * Reference easeOutQuad:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseQuadraticActionOut
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeQuadraticActionOut())
- *
- * @example
- * action.easing(cc.easeQuadraticActionOut());
- */
-cc.EaseQuadraticActionOut = cc.ActionEase.extend({
-
- _updateTime: function(time){
- return -time*(time-2);
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseQuadraticActionOut();
- action.initWithAction();
- return action;
- },
-
- reverse: function(){
- return new cc.EaseQuadraticActionOut(this._inner.reverse());
- }
-});
-
-cc._easeQuadraticActionOut = {
- easing: cc.EaseQuadraticActionOut.prototype._updateTime,
- reverse: function(){
- return cc._easeQuadraticActionOut;
- }
-};
/**
* !#en
* Creates the action easing object.
@@ -1606,55 +656,16 @@ cc._easeQuadraticActionOut = {
* //example
* action.easing(cc.easeQuadraticActionOut());
*/
-cc.easeQuadraticActionOut = function(){
- return cc._easeQuadraticActionOut;
+var _easeQuadraticActionOut = {
+ easing: function(time){
+ return -time*(time-2);
+ },
+ reverse: function(){
+ return _easeQuadraticActionOut;
+ }
};
-
-/*
- * cc.EaseQuadraticActionInOut action.
- * Reference easeInOutQuad:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseQuadraticActionInOut
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeQuadraticActionInOut())
- *
- * @example
- * action.easing(cc.easeQuadraticActionInOut());
- */
-cc.EaseQuadraticActionInOut = cc.ActionEase.extend({
- _updateTime: function(time){
- var resultTime = time;
- time *= 2;
- if(time < 1){
- resultTime = time * time * 0.5;
- }else{
- --time;
- resultTime = -0.5 * ( time * ( time - 2 ) - 1)
- }
- return resultTime;
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseQuadraticActionInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseQuadraticActionInOut(this._inner.reverse());
- }
-});
-
-cc._easeQuadraticActionInOut = {
- easing: cc.EaseQuadraticActionInOut.prototype._updateTime,
- reverse: function(){
- return cc._easeQuadraticActionInOut;
- }
+cc.easeQuadraticActionOut = function(){
+ return _easeQuadraticActionOut;
};
/**
@@ -1672,48 +683,26 @@ cc._easeQuadraticActionInOut = {
* //example
* action.easing(cc.easeQuadraticActionInOut());
*/
+var _easeQuadraticActionInOut = {
+ easing: function(time){
+ var resultTime = time;
+ time *= 2;
+ if(time < 1){
+ resultTime = time * time * 0.5;
+ }else{
+ --time;
+ resultTime = -0.5 * ( time * ( time - 2 ) - 1)
+ }
+ return resultTime;
+ },
+ reverse: function(){
+ return _easeQuadraticActionInOut;
+ }
+};
cc.easeQuadraticActionInOut = function(){
- return cc._easeQuadraticActionInOut;
+ return _easeQuadraticActionInOut;
};
-/*
- * cc.EaseQuarticActionIn action.
- * Reference easeInQuart:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseQuarticActionIn
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeQuarticActionIn());
- *
- * @example
- * action.easing(cc.easeQuarticActionIn());
- */
-cc.EaseQuarticActionIn = cc.ActionEase.extend({
- _updateTime: function(time){
- return time * time * time * time;
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseQuarticActionIn();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseQuarticActionIn(this._inner.reverse());
- }
-});
-
-cc._easeQuarticActionIn = {
- easing: cc.EaseQuarticActionIn.prototype._updateTime,
- reverse: function(){
- return cc._easeQuarticActionIn;
- }
-};
/**
* !#en
* Creates the action easing object.
@@ -1729,48 +718,16 @@ cc._easeQuarticActionIn = {
* //example
* action.easing(cc.easeQuarticActionIn());
*/
-cc.easeQuarticActionIn = function(){
- return cc._easeQuarticActionIn;
+var _easeQuarticActionIn = {
+ easing: function(time){
+ return time * time * time * time;
+ },
+ reverse: function(){
+ return _easeQuarticActionIn;
+ }
};
-
-/*
- * cc.EaseQuarticActionOut action.
- * Reference easeOutQuart:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseQuarticActionOut
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.QuarticActionOut());
- *
- * @example
- * action.easing(cc.EaseQuarticActionOut());
- */
-cc.EaseQuarticActionOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time -= 1;
- return -(time * time * time * time - 1);
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseQuarticActionOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseQuarticActionOut(this._inner.reverse());
- }
-});
-
-cc._easeQuarticActionOut = {
- easing: cc.EaseQuarticActionOut.prototype._updateTime,
- reverse: function(){
- return cc._easeQuarticActionOut;
- }
+cc.easeQuarticActionIn = function(){
+ return _easeQuarticActionIn;
};
/**
@@ -1788,52 +745,19 @@ cc._easeQuarticActionOut = {
* //example
* action.easing(cc.QuarticActionOut());
*/
+var _easeQuarticActionOut = {
+ easing: function(time){
+ time -= 1;
+ return -(time * time * time * time - 1);
+ },
+ reverse: function(){
+ return _easeQuarticActionOut;
+ }
+};
cc.easeQuarticActionOut = function(){
- return cc._easeQuarticActionOut;
+ return _easeQuarticActionOut;
};
-/*
- * cc.EaseQuarticActionInOut action.
- * Reference easeInOutQuart:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseQuarticActionInOut
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeQuarticActionInOut());
- *
- * @example
- * action.easing(cc.easeQuarticActionInOut());
- */
-cc.EaseQuarticActionInOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time = time*2;
- if (time < 1)
- return 0.5 * time * time * time * time;
- time -= 2;
- return -0.5 * (time * time * time * time - 2);
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseQuarticActionInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseQuarticActionInOut(this._inner.reverse());
- }
-});
-
-cc._easeQuarticActionInOut = {
- easing: cc.EaseQuarticActionInOut.prototype._updateTime,
- reverse: function(){
- return cc._easeQuarticActionInOut;
- }
-};
/**
* !#en
* Creates the action easing object.
@@ -1846,47 +770,20 @@ cc._easeQuarticActionInOut = {
* @method easeQuarticActionInOut
* @returns {Object}
*/
-cc.easeQuarticActionInOut = function(){
- return cc._easeQuarticActionInOut;
+var _easeQuarticActionInOut = {
+ easing: function(time){
+ time = time*2;
+ if (time < 1)
+ return 0.5 * time * time * time * time;
+ time -= 2;
+ return -0.5 * (time * time * time * time - 2);
+ },
+ reverse: function(){
+ return _easeQuarticActionInOut;
+ }
};
-
-/*
- * cc.EaseQuinticActionIn action.
- * Reference easeInQuint:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseQuinticActionIn
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeQuinticActionIn());
- *
- * @example
- * action.easing(cc.easeQuinticActionIn());
- */
-cc.EaseQuinticActionIn = cc.ActionEase.extend({
- _updateTime: function(time){
- return time * time * time * time * time;
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseQuinticActionIn();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseQuinticActionIn(this._inner.reverse());
- }
-});
-
-cc._easeQuinticActionIn = {
- easing: cc.EaseQuinticActionIn.prototype._updateTime,
- reverse: function(){
- return cc._easeQuinticActionIn;
- }
+cc.easeQuarticActionInOut = function(){
+ return _easeQuarticActionInOut;
};
/**
@@ -1904,48 +801,16 @@ cc._easeQuinticActionIn = {
* //example
* action.easing(cc.easeQuinticActionIn());
*/
-cc.easeQuinticActionIn = function(){
- return cc._easeQuinticActionIn;
+var _easeQuinticActionIn = {
+ easing: function(time){
+ return time * time * time * time * time;
+ },
+ reverse: function(){
+ return _easeQuinticActionIn;
+ }
};
-
-/*
- * cc.EaseQuinticActionOut action.
- * Reference easeQuint:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseQuinticActionOut
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeQuadraticActionOut());
- *
- * @example
- * action.easing(cc.easeQuadraticActionOut());
- */
-cc.EaseQuinticActionOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time -=1;
- return (time * time * time * time * time + 1);
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseQuinticActionOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseQuinticActionOut(this._inner.reverse());
- }
-});
-
-cc._easeQuinticActionOut = {
- easing: cc.EaseQuinticActionOut.prototype._updateTime,
- reverse: function(){
- return cc._easeQuinticActionOut;
- }
+cc.easeQuinticActionIn = function(){
+ return _easeQuinticActionIn;
};
/**
@@ -1963,51 +828,17 @@ cc._easeQuinticActionOut = {
* //example
* action.easing(cc.easeQuadraticActionOut());
*/
-cc.easeQuinticActionOut = function(){
- return cc._easeQuinticActionOut;
+var _easeQuinticActionOut = {
+ easing: function(time){
+ time -=1;
+ return (time * time * time * time * time + 1);
+ },
+ reverse: function(){
+ return _easeQuinticActionOut;
+ }
};
-
-/*
- * cc.EaseQuinticActionInOut action.
- * Reference easeInOutQuint:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseQuinticActionInOut
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeQuinticActionInOut());
- *
- * @example
- * action.easing(cc.easeQuinticActionInOut());
- */
-cc.EaseQuinticActionInOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time = time*2;
- if (time < 1)
- return 0.5 * time * time * time * time * time;
- time -= 2;
- return 0.5 * (time * time * time * time * time + 2);
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseQuinticActionInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseQuinticActionInOut(this._inner.reverse());
- }
-});
-
-cc._easeQuinticActionInOut = {
- easing: cc.EaseQuinticActionInOut.prototype._updateTime,
- reverse: function(){
- return cc._easeQuinticActionInOut;
- }
+cc.easeQuinticActionOut = function(){
+ return _easeQuinticActionOut;
};
/**
@@ -2025,47 +856,20 @@ cc._easeQuinticActionInOut = {
* //example
* action.easing(cc.easeQuinticActionInOut());
*/
-cc.easeQuinticActionInOut = function(){
- return cc._easeQuinticActionInOut;
+var _easeQuinticActionInOut = {
+ easing: function(time){
+ time = time*2;
+ if (time < 1)
+ return 0.5 * time * time * time * time * time;
+ time -= 2;
+ return 0.5 * (time * time * time * time * time + 2);
+ },
+ reverse: function(){
+ return _easeQuinticActionInOut;
+ }
};
-
-/*
- * cc.EaseCircleActionIn action.
- * Reference easeInCirc:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseCircleActionIn
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeCircleActionIn());
- *
- * @example
- * action.easing(cc.easeCircleActionIn());
- */
-cc.EaseCircleActionIn = cc.ActionEase.extend({
- _updateTime: function(time){
- return -1 * (Math.sqrt(1 - time * time) - 1);
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseCircleActionIn();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseCircleActionIn(this._inner.reverse());
- }
-});
-
-cc._easeCircleActionIn = {
- easing: cc.EaseCircleActionIn.prototype._updateTime,
- reverse: function(){
- return cc._easeCircleActionIn;
- }
+cc.easeQuinticActionInOut = function(){
+ return _easeQuinticActionInOut;
};
/**
@@ -2083,48 +887,16 @@ cc._easeCircleActionIn = {
* //example
* action.easing(cc.easeCircleActionIn());
*/
-cc.easeCircleActionIn = function(){
- return cc._easeCircleActionIn;
+var _easeCircleActionIn = {
+ easing: function(time){
+ return -1 * (Math.sqrt(1 - time * time) - 1);
+ },
+ reverse: function(){
+ return _easeCircleActionIn;
+ }
};
-
-/*
- * cc.EaseCircleActionOut action.
- * Reference easeOutCirc:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseCircleActionOut
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeCircleActionOut());
- *
- * @example
- * action.easing(cc.easeCircleActionOut());
- */
-cc.EaseCircleActionOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time = time - 1;
- return Math.sqrt(1 - time * time);
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseCircleActionOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseCircleActionOut(this._inner.reverse());
- }
-});
-
-cc._easeCircleActionOut = {
- easing: cc.EaseCircleActionOut.prototype._updateTime,
- reverse: function(){
- return cc._easeCircleActionOut;
- }
+cc.easeCircleActionIn = function(){
+ return _easeCircleActionIn;
};
/**
@@ -2142,51 +914,17 @@ cc._easeCircleActionOut = {
* //example
* actioneasing(cc.easeCircleActionOut());
*/
-cc.easeCircleActionOut = function(){
- return cc._easeCircleActionOut;
+var _easeCircleActionOut = {
+ easing: function(time){
+ time = time - 1;
+ return Math.sqrt(1 - time * time);
+ },
+ reverse: function(){
+ return _easeCircleActionOut;
+ }
};
-
-/*
- * cc.EaseCircleActionInOut action.
- * Reference easeInOutCirc:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseCircleActionInOut
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeCircleActionInOut());
- *
- * @example
- * action.easing(cc.easeCircleActionInOut());
- */
-cc.EaseCircleActionInOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time = time * 2;
- if (time < 1)
- return -0.5 * (Math.sqrt(1 - time * time) - 1);
- time -= 2;
- return 0.5 * (Math.sqrt(1 - time * time) + 1);
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseCircleActionInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseCircleActionInOut(this._inner.reverse());
- }
-});
-
-cc._easeCircleActionInOut = {
- easing: cc.EaseCircleActionInOut.prototype._updateTime,
- reverse: function(){
- return cc._easeCircleActionInOut;
- }
+cc.easeCircleActionOut = function(){
+ return _easeCircleActionOut;
};
/**
@@ -2204,47 +942,20 @@ cc._easeCircleActionInOut = {
* //example
* action.easing(cc.easeCircleActionInOut());
*/
-cc.easeCircleActionInOut = function(){
- return cc._easeCircleActionInOut;
+var _easeCircleActionInOut = {
+ easing: function(time){
+ time = time * 2;
+ if (time < 1)
+ return -0.5 * (Math.sqrt(1 - time * time) - 1);
+ time -= 2;
+ return 0.5 * (Math.sqrt(1 - time * time) + 1);
+ },
+ reverse: function(){
+ return _easeCircleActionInOut;
+ }
};
-
-/*
- * cc.EaseCubicActionIn action.
- * Reference easeInCubic:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseCubicActionIn
- * @extends ActionEase
- *
- * @deprecated since v3.0
action.easing(cc.easeCubicActionIn());
- *
- * @example
- * action.easing(cc.easeCubicActionIn());
- */
-cc.EaseCubicActionIn = cc.ActionEase.extend({
- _updateTime: function(time){
- return time * time * time;
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseCubicActionIn();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseCubicActionIn(this._inner.reverse());
- }
-});
-
-cc._easeCubicActionIn = {
- easing: cc.EaseCubicActionIn.prototype._updateTime,
- reverse: function(){
- return cc._easeCubicActionIn;
- }
+cc.easeCircleActionInOut = function(){
+ return _easeCircleActionInOut;
};
/**
@@ -2262,48 +973,16 @@ cc._easeCubicActionIn = {
* //example
* action.easing(cc.easeCubicActionIn());
*/
-cc.easeCubicActionIn = function(){
- return cc._easeCubicActionIn;
+var _easeCubicActionIn = {
+ easing: function(time){
+ return time * time * time;
+ },
+ reverse: function(){
+ return _easeCubicActionIn;
+ }
};
-
-/*
- * cc.EaseCubicActionOut action.
- * Reference easeOutCubic:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseCubicActionOut
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeCubicActionOut());
- *
- * @example
- * action.easing(cc.easeCubicActionOut());
- */
-cc.EaseCubicActionOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time -= 1;
- return (time * time * time + 1);
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseCubicActionOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseCubicActionOut(this._inner.reverse());
- }
-});
-
-cc._easeCubicActionOut = {
- easing: cc.EaseCubicActionOut.prototype._updateTime,
- reverse: function(){
- return cc._easeCubicActionOut;
- }
+cc.easeCubicActionIn = function(){
+ return _easeCubicActionIn;
};
/**
@@ -2321,51 +1000,17 @@ cc._easeCubicActionOut = {
* //example
* action.easing(cc.easeCubicActionOut());
*/
-cc.easeCubicActionOut = function(){
- return cc._easeCubicActionOut;
+var _easeCubicActionOut = {
+ easing: function(time){
+ time -= 1;
+ return (time * time * time + 1);
+ },
+ reverse: function(){
+ return _easeCubicActionOut;
+ }
};
-
-/*
- * cc.EaseCubicActionInOut action.
- * Reference easeInOutCubic:
- * http://www.zhihu.com/question/21981571/answer/19925418
- * @class EaseCubicActionInOut
- * @extends ActionEase
- *
- * @deprecated since v3.0
Please use action.easing(cc.easeCubicActionInOut());
- *
- * @example
- * action.easing(cc.easeCubicActionInOut());
- */
-cc.EaseCubicActionInOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time = time*2;
- if (time < 1)
- return 0.5 * time * time * time;
- time -= 2;
- return 0.5 * (time * time * time + 2);
- },
-
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
-
- clone: function(){
- var action = new cc.EaseCubicActionInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
-
- reverse: function(){
- return new cc.EaseCubicActionInOut(this._inner.reverse());
- }
-});
-
-cc._easeCubicActionInOut = {
- easing: cc.EaseCubicActionInOut.prototype._updateTime,
- reverse: function(){
- return cc._easeCubicActionInOut;
- }
+cc.easeCubicActionOut = function(){
+ return _easeCubicActionOut;
};
/**
@@ -2380,7 +1025,19 @@ cc._easeCubicActionInOut = {
* @method easeCubicActionInOut
* @returns {Object}
*/
+var _easeCubicActionInOut = {
+ easing: function(time){
+ time = time*2;
+ if (time < 1)
+ return 0.5 * time * time * time;
+ time -= 2;
+ return 0.5 * (time * time * time + 2);
+ },
+ reverse: function(){
+ return _easeCubicActionInOut;
+ }
+};
cc.easeCubicActionInOut = function(){
- return cc._easeCubicActionInOut;
+ return _easeCubicActionInOut;
};
diff --git a/cocos2d/actions/CCActionInstant.js b/cocos2d/actions/CCActionInstant.js
index 1727cc34ed..b90b3bb3b6 100644
--- a/cocos2d/actions/CCActionInstant.js
+++ b/cocos2d/actions/CCActionInstant.js
@@ -34,7 +34,9 @@
* @class ActionInstant
* @extends FiniteTimeAction
*/
-cc.ActionInstant = cc.FiniteTimeAction.extend({
+cc.ActionInstant = cc.Class({
+ name: 'cc.ActionInstant',
+ extends: cc.FiniteTimeAction,
isDone:function () {
return true;
},
@@ -72,7 +74,9 @@ cc.ActionInstant = cc.FiniteTimeAction.extend({
* @class Show
* @extends ActionInstant
*/
-cc.Show = cc.ActionInstant.extend({
+cc.Show = cc.Class({
+ name: 'cc.Show',
+ extends: cc.ActionInstant,
update:function (dt) {
var _renderComps = this.target.getComponentsInChildren(cc._SGComponent);
@@ -109,7 +113,9 @@ cc.show = function () {
* @class Hide
* @extends ActionInstant
*/
-cc.Hide = cc.ActionInstant.extend({
+cc.Hide = cc.Class({
+ name: 'cc.Hide',
+ extends: cc.ActionInstant,
update:function (dt) {
var _renderComps = this.target.getComponentsInChildren(cc._SGComponent);
@@ -146,7 +152,9 @@ cc.hide = function () {
* @class ToggleVisibility
* @extends ActionInstant
*/
-cc.ToggleVisibility = cc.ActionInstant.extend({
+cc.ToggleVisibility = cc.Class({
+ name: 'cc.ToggleVisibility',
+ extends: cc.ActionInstant,
update:function (dt) {
var _renderComps = this.target.getComponentsInChildren(cc._SGComponent);
@@ -188,12 +196,12 @@ cc.toggleVisibility = function () {
* // example
* var removeSelfAction = new cc.RemoveSelf(false);
*/
-cc.RemoveSelf = cc.ActionInstant.extend({
- _isNeedCleanUp: true,
+cc.RemoveSelf = cc.Class({
+ name: 'cc.RemoveSelf',
+ extends: cc.ActionInstant,
ctor:function(isNeedCleanUp){
- cc.FiniteTimeAction.prototype.ctor.call(this);
-
+ this._isNeedCleanUp = true;
isNeedCleanUp !== undefined && this.init(isNeedCleanUp);
},
@@ -239,11 +247,11 @@ cc.removeSelf = function(isNeedCleanUp){
* @example
* var flipXAction = new cc.FlipX(true);
*/
-cc.FlipX = cc.ActionInstant.extend({
- _flippedX:false,
+cc.FlipX = cc.Class({
+ name: 'cc.FlipX',
+ extends: cc.ActionInstant,
ctor:function(flip){
- cc.FiniteTimeAction.prototype.ctor.call(this);
this._flippedX = false;
flip !== undefined && this.initWithFlipX(flip);
},
@@ -294,13 +302,12 @@ cc.flipX = function (flip) {
* @example
* var flipYAction = new cc.FlipY(true);
*/
-cc.FlipY = cc.ActionInstant.extend({
- _flippedY:false,
+cc.FlipY = cc.Class({
+ name: 'cc.FlipY',
+ extends: cc.ActionInstant,
ctor: function(flip){
- cc.FiniteTimeAction.prototype.ctor.call(this);
this._flippedY = false;
-
flip !== undefined && this.initWithFlipY(flip);
},
@@ -352,12 +359,11 @@ cc.flipY = function (flip) {
* var placeAction = new cc.Place(cc.p(200, 200));
* var placeAction = new cc.Place(200, 200);
*/
-cc.Place = cc.ActionInstant.extend({
- _x: 0,
- _y: 0,
+cc.Place = cc.Class({
+ name: 'cc.Place',
+ extends: cc.ActionInstant,
ctor:function(pos, y){
- cc.FiniteTimeAction.prototype.ctor.call(this);
this._x = 0;
this._y = 0;
@@ -425,10 +431,9 @@ cc.place = function (pos, y) {
* // CallFunc with data
* var finish = new cc.CallFunc(this.removeFromParentAndCleanup, this, true);
*/
-cc.CallFunc = cc.ActionInstant.extend({
- _selectorTarget:null,
- _function:null,
- _data:null,
+cc.CallFunc = cc.Class({
+ name: 'cc.CallFunc',
+ extends: cc.ActionInstant,
/*
* Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
@@ -438,8 +443,9 @@ cc.CallFunc = cc.ActionInstant.extend({
* @param {*} [data=null] data for function, it accepts all data types.
*/
ctor:function(selector, selectorTarget, data){
- cc.FiniteTimeAction.prototype.ctor.call(this);
-
+ this._selectorTarget = null;
+ this._function = null;
+ this._data = null;
this.initWithFunction(selector, selectorTarget, data);
},
diff --git a/cocos2d/actions/CCActionInterval.js b/cocos2d/actions/CCActionInterval.js
index 97d3f71d0e..244fecdaa8 100644
--- a/cocos2d/actions/CCActionInterval.js
+++ b/cocos2d/actions/CCActionInterval.js
@@ -46,24 +46,20 @@
* @extends FiniteTimeAction
* @param {Number} d duration in seconds
*/
-cc.ActionInterval = cc.FiniteTimeAction.extend({
- _elapsed:0,
- _firstTick:false,
- _easeList: null,
- _timesForRepeat:1,
- _repeatForever: false,
- _repeatMethod: false,//Compatible with repeat class, Discard after can be deleted
- _speed: 1,
- _speedMethod: false,//Compatible with speed class, Discard after can be deleted
+cc.ActionInterval = cc.Class({
+ name: 'cc.ActionInterval',
+ extends: cc.FiniteTimeAction,
ctor:function (d) {
+ this.MAX_VALUE = 2;
+ this._elapsed = 0;
+ this._firstTick = false;
+ this._easeList = null;
this._speed = 1;
this._timesForRepeat = 1;
this._repeatForever = false;
- this.MAX_VALUE = 2;
this._repeatMethod = false;//Compatible with repeat class, Discard after can be deleted
this._speedMethod = false;//Compatible with repeat class, Discard after can be deleted
- cc.FiniteTimeAction.prototype.ctor.call(this);
d !== undefined && this.initWithDuration(d);
},
@@ -302,15 +298,15 @@ cc.actionInterval = function (d) {
* // create sequence with array
* var seq = new cc.Sequence(actArray);
*/
-cc.Sequence = cc.ActionInterval.extend({
- _actions:null,
- _split:null,
- _last:0,
- _reversed:false,
+cc.Sequence = cc.Class({
+ name: 'cc.Sequence',
+ extends: cc.ActionInterval,
ctor:function (tempArray) {
- cc.ActionInterval.prototype.ctor.call(this);
this._actions = [];
+ this._split = null;
+ this._last = 0;
+ this._reversed = false;
var paramArray = (tempArray instanceof Array) ? tempArray : arguments;
if (paramArray.length === 1) {
@@ -486,16 +482,16 @@ cc.Sequence._actionOneTwo = function (actionOne, actionTwo) {
* @example
* var rep = new cc.Repeat(cc.sequence(jump2, jump1), 5);
*/
-cc.Repeat = cc.ActionInterval.extend({
- _times:0,
- _total:0,
- _nextDt:0,
- _actionInstant:false,
- _innerAction:null, //CCFiniteTimeAction
+cc.Repeat = cc.Class({
+ name: 'cc.Repeat',
+ extends: cc.ActionInterval,
ctor: function (action, times) {
- cc.ActionInterval.prototype.ctor.call(this);
-
+ this._times = 0;
+ this._total = 0;
+ this._nextDt = 0;
+ this._actionInstant = false;
+ this._innerAction = null;
times !== undefined && this.initWithAction(action, times);
},
@@ -633,13 +629,12 @@ cc.repeat = function (action, times) {
* @example
* var rep = new cc.RepeatForever(cc.sequence(jump2, jump1), 5);
*/
-cc.RepeatForever = cc.ActionInterval.extend({
- _innerAction:null, //CCActionInterval
+cc.RepeatForever = cc.Class({
+ name: 'cc.RepeatForever',
+ extends: cc.ActionInterval,
ctor:function (action) {
- cc.ActionInterval.prototype.ctor.call(this);
this._innerAction = null;
-
action && this.initWithAction(action);
},
@@ -730,12 +725,11 @@ cc.repeatForever = function (action) {
* @class Spawn
* @extends ActionInterval
*/
-cc.Spawn = cc.ActionInterval.extend({
- _one:null,
- _two:null,
+cc.Spawn = cc.Class({
+ name: 'cc.Spawn',
+ extends: cc.ActionInterval,
ctor:function (tempArray) {
- cc.ActionInterval.prototype.ctor.call(this);
this._one = null;
this._two = null;
@@ -871,18 +865,17 @@ cc.Spawn._actionOneTwo = function (action1, action2) {
* @example
* var rotateTo = new cc.RotateTo(2, 61.0);
*/
-cc.RotateTo = cc.ActionInterval.extend({
- _dstAngleX:0,
- _startAngleX:0,
- _diffAngleX:0,
-
- _dstAngleY:0,
- _startAngleY:0,
- _diffAngleY:0,
+cc.RotateTo = cc.Class({
+ name: 'cc.RotateTo',
+ extends: cc.ActionInterval,
ctor:function (duration, deltaAngleX, deltaAngleY) {
- cc.ActionInterval.prototype.ctor.call(this);
-
+ this._dstAngleX = 0;
+ this._startAngleX = 0;
+ this._diffAngleX = 0;
+ this._dstAngleY = 0;
+ this._startAngleY = 0;
+ this._diffAngleY = 0;
deltaAngleX !== undefined && this.initWithDuration(duration, deltaAngleX, deltaAngleY);
},
@@ -975,15 +968,15 @@ cc.rotateTo = function (duration, deltaAngleX, deltaAngleY) {
* @example
* var actionBy = new cc.RotateBy(2, 360);
*/
-cc.RotateBy = cc.ActionInterval.extend({
- _angleX:0,
- _startAngleX:0,
- _angleY:0,
- _startAngleY:0,
+cc.RotateBy = cc.Class({
+ name: 'cc.RotateBy',
+ extends: cc.ActionInterval,
ctor: function (duration, deltaAngleX, deltaAngleY) {
- cc.ActionInterval.prototype.ctor.call(this);
-
+ this._angleX = 0;
+ this._startAngleX = 0;
+ this._angleY = 0;
+ this._startAngleY = 0;
deltaAngleX !== undefined && this.initWithDuration(duration, deltaAngleX, deltaAngleY);
},
@@ -1066,14 +1059,11 @@ cc.rotateBy = function (duration, deltaAngleX, deltaAngleY) {
* @example
* var actionTo = cc.moveBy(2, cc.p(windowSize.width - 40, windowSize.height - 40));
*/
-cc.MoveBy = cc.ActionInterval.extend({
- _positionDelta:null,
- _startPosition:null,
- _previousPosition:null,
+cc.MoveBy = cc.Class({
+ name: 'cc.MoveBy',
+ extends: cc.ActionInterval,
ctor:function (duration, deltaPos, deltaY) {
- cc.ActionInterval.prototype.ctor.call(this);
-
this._positionDelta = cc.p(0, 0);
this._startPosition = cc.p(0, 0);
this._previousPosition = cc.p(0, 0);
@@ -1184,13 +1174,12 @@ cc.moveBy = function (duration, deltaPos, deltaY) {
* @example
* var actionBy = new cc.MoveTo(2, cc.p(80, 80));
*/
-cc.MoveTo = cc.MoveBy.extend({
- _endPosition:null,
+cc.MoveTo = cc.Class({
+ name: 'cc.MoveTo',
+ extends: cc.MoveBy,
ctor:function (duration, position, y) {
- cc.MoveBy.prototype.ctor.call(this);
this._endPosition = cc.p(0, 0);
-
position !== undefined && this.initWithDuration(duration, position, y);
},
@@ -1258,19 +1247,19 @@ cc.moveTo = function (duration, position, y) {
* @example
* var actionTo = new cc.SkewTo(2, 37.2, -37.2);
*/
-cc.SkewTo = cc.ActionInterval.extend({
- _skewX:0,
- _skewY:0,
- _startSkewX:0,
- _startSkewY:0,
- _endSkewX:0,
- _endSkewY:0,
- _deltaX:0,
- _deltaY:0,
+cc.SkewTo = cc.Class({
+ name: 'cc.SkewTo',
+ extends: cc.ActionInterval,
ctor: function (t, sx, sy) {
- cc.ActionInterval.prototype.ctor.call(this);
-
+ this._skewX = 0;
+ this._skewY = 0;
+ this._startSkewX = 0;
+ this._startSkewY = 0;
+ this._endSkewX = 0;
+ this._endSkewY = 0;
+ this._deltaX = 0;
+ this._deltaY = 0;
sy !== undefined && this.initWithDuration(t, sx, sy);
},
@@ -1350,10 +1339,11 @@ cc.skewTo = function (t, sx, sy) {
* @param {Number} sx skew in degrees for X axis
* @param {Number} sy skew in degrees for Y axis
*/
-cc.SkewBy = cc.SkewTo.extend({
+cc.SkewBy = cc.Class({
+ name: 'cc.SkewBy',
+ extends: cc.SkewTo,
ctor: function(t, sx, sy) {
- cc.SkewTo.prototype.ctor.call(this);
sy !== undefined && this.initWithDuration(t, sx, sy);
},
@@ -1430,18 +1420,16 @@ cc.skewBy = function (t, sx, sy) {
* var actionBy = new cc.JumpBy(2, cc.p(300, 0), 50, 4);
* var actionBy = new cc.JumpBy(2, 300, 0, 50, 4);
*/
-cc.JumpBy = cc.ActionInterval.extend({
- _startPosition:null,
- _delta:null,
- _height:0,
- _jumps:0,
- _previousPosition:null,
+cc.JumpBy = cc.Class({
+ name: 'cc.JumpBy',
+ extends: cc.ActionInterval,
ctor:function (duration, position, y, height, jumps) {
- cc.ActionInterval.prototype.ctor.call(this);
this._startPosition = cc.p(0, 0);
this._previousPosition = cc.p(0, 0);
this._delta = cc.p(0, 0);
+ this._height = 0;
+ this._jumps = 0;
height !== undefined && this.initWithDuration(duration, position, y, height, jumps);
},
@@ -1561,13 +1549,12 @@ cc.jumpBy = function (duration, position, y, height, jumps) {
* var actionTo = new cc.JumpTo(2, cc.p(300, 0), 50, 4);
* var actionTo = new cc.JumpTo(2, 300, 0, 50, 4);
*/
-cc.JumpTo = cc.JumpBy.extend({
- _endPosition:null,
+cc.JumpTo = cc.Class({
+ name: 'cc.JumpTo',
+ extends: cc.JumpBy,
ctor:function (duration, position, y, height, jumps) {
- cc.JumpBy.prototype.ctor.call(this);
this._endPosition = cc.p(0, 0);
-
height !== undefined && this.initWithDuration(duration, position, y, height, jumps);
},
/*
@@ -1630,22 +1617,6 @@ cc.jumpTo = function (duration, position, y, height, jumps) {
return new cc.JumpTo(duration, position, y, height, jumps);
};
-/*
- * @method bezierAt
- * @param {Number} a
- * @param {Number} b
- * @param {Number} c
- * @param {Number} d
- * @param {Number} t
- * @return {Number}
- */
-cc.bezierAt = function (a, b, c, d, t) {
- return (Math.pow(1 - t, 3) * a +
- 3 * t * (Math.pow(1 - t, 2)) * b +
- 3 * Math.pow(t, 2) * (1 - t) * c +
- Math.pow(t, 3) * d );
-};
-
/* An action that moves the target with a cubic Bezier curve by a certain distance.
* Relative to its movement.
* @class BezierBy
@@ -1656,17 +1627,20 @@ cc.bezierAt = function (a, b, c, d, t) {
* var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)];
* var bezierForward = new cc.BezierBy(3, bezier);
*/
-cc.BezierBy = cc.ActionInterval.extend({
- _config:null,
- _startPosition:null,
- _previousPosition:null,
+function bezierAt (a, b, c, d, t) {
+ return (Math.pow(1 - t, 3) * a +
+ 3 * t * (Math.pow(1 - t, 2)) * b +
+ 3 * Math.pow(t, 2) * (1 - t) * c +
+ Math.pow(t, 3) * d );
+};
+cc.BezierBy = cc.Class({
+ name: 'cc.BezierBy',
+ extends: cc.ActionInterval,
ctor:function (t, c) {
- cc.ActionInterval.prototype.ctor.call(this);
this._config = [];
this._startPosition = cc.p(0, 0);
this._previousPosition = cc.p(0, 0);
-
c && this.initWithDuration(t, c);
},
@@ -1720,8 +1694,8 @@ cc.BezierBy = cc.ActionInterval.extend({
var yc = locConfig[1].y;
var yd = locConfig[2].y;
- var x = cc.bezierAt(xa, xb, xc, xd, dt);
- var y = cc.bezierAt(ya, yb, yc, yd, dt);
+ var x = bezierAt(xa, xb, xc, xd, dt);
+ var y = bezierAt(ya, yb, yc, yd, dt);
var locStartPosition = this._startPosition;
if (cc.macro.ENABLE_STACKABLE_ACTIONS) {
@@ -1783,11 +1757,11 @@ cc.bezierBy = function (t, c) {
* var bezier = [cc.p(0, windowSize.height / 2), cc.p(300, -windowSize.height / 2), cc.p(300, 100)];
* var bezierTo = new cc.BezierTo(2, bezier);
*/
-cc.BezierTo = cc.BezierBy.extend({
- _toConfig:null,
+cc.BezierTo = cc.Class({
+ name: 'cc.BezierTo',
+ extends: cc.BezierBy,
ctor:function (t, c) {
- cc.BezierBy.prototype.ctor.call(this);
this._toConfig = [];
c && this.initWithDuration(t, c);
},
@@ -1855,18 +1829,19 @@ cc.bezierTo = function (t, c) {
* // It scales to 0.5 in x and 2 in Y
* var actionTo = new cc.ScaleTo(2, 0.5, 2);
*/
-cc.ScaleTo = cc.ActionInterval.extend({
- _scaleX:1,
- _scaleY:1,
- _startScaleX:1,
- _startScaleY:1,
- _endScaleX:0,
- _endScaleY:0,
- _deltaX:0,
- _deltaY:0,
+cc.ScaleTo = cc.Class({
+ name: 'cc.ScaleTo',
+ extends: cc.ActionInterval,
ctor:function (duration, sx, sy) {
- cc.ActionInterval.prototype.ctor.call(this);
+ this._scaleX = 1;
+ this._scaleY = 1;
+ this._startScaleX = 1;
+ this._startScaleY = 1;
+ this._endScaleX = 0;
+ this._endScaleY = 0;
+ this._deltaX = 0;
+ this._deltaY = 0;
sx !== undefined && this.initWithDuration(duration, sx, sy);
},
@@ -1935,7 +1910,10 @@ cc.scaleTo = function (duration, sx, sy) { //function overload
* @class ScaleBy
* @extends ScaleTo
*/
-cc.ScaleBy = cc.ScaleTo.extend({
+cc.ScaleBy = cc.Class({
+ name: 'cc.ScaleBy',
+ extends: cc.ScaleTo,
+
startWithTarget:function (target) {
cc.ScaleTo.prototype.startWithTarget.call(this, target);
this._deltaX = this._startScaleX * this._endScaleX - this._startScaleX;
@@ -1985,12 +1963,13 @@ cc.scaleBy = function (duration, sx, sy) {
* @example
* var action = new cc.Blink(2, 10);
*/
-cc.Blink = cc.ActionInterval.extend({
- _times:0,
- _originalState:false,
+cc.Blink = cc.Class({
+ name: 'cc.Blink',
+ extends: cc.ActionInterval,
ctor:function (duration, blinks) {
- cc.ActionInterval.prototype.ctor.call(this);
+ this._times = 0;
+ this._originalState = false;
blinks !== undefined && this.initWithDuration(duration, blinks);
},
@@ -2065,12 +2044,13 @@ cc.blink = function (duration, blinks) {
* @example
* var action = new cc.FadeTo(1.0, 0);
*/
-cc.FadeTo = cc.ActionInterval.extend({
- _toOpacity:0,
- _fromOpacity:0,
+cc.FadeTo = cc.Class({
+ name: 'cc.FadeTo',
+ extends: cc.ActionInterval,
ctor:function (duration, opacity) {
- cc.ActionInterval.prototype.ctor.call(this);
+ this._toOpacity = 0;
+ this._fromOpacity = 0;
opacity !== undefined && this.initWithDuration(duration, opacity);
},
@@ -2130,13 +2110,14 @@ cc.fadeTo = function (duration, opacity) {
* @extends FadeTo
* @param {Number} duration duration in seconds
*/
-cc.FadeIn = cc.FadeTo.extend({
- _reverseAction: null,
+cc.FadeIn = cc.Class({
+ name: 'cc.FadeIn',
+ extends: cc.FadeTo,
ctor:function (duration) {
- cc.FadeTo.prototype.ctor.call(this);
if (duration == null)
duration = 0;
+ this._reverseAction = null;
this.initWithDuration(duration, 255);
},
@@ -2183,12 +2164,14 @@ cc.fadeIn = function (duration) {
* @extends FadeTo
* @param {Number} duration duration in seconds
*/
-cc.FadeOut = cc.FadeTo.extend({
+cc.FadeOut = cc.Class({
+ name: 'cc.FadeOut',
+ extends: cc.FadeTo,
ctor:function (duration) {
- cc.FadeTo.prototype.ctor.call(this);
if (duration == null)
duration = 0;
+ this._reverseAction = null;
this.initWithDuration(duration, 0);
},
@@ -2234,12 +2217,11 @@ cc.fadeOut = function (d) {
* @example
* var action = new cc.TintTo(2, 255, 0, 255);
*/
-cc.TintTo = cc.ActionInterval.extend({
- _to:null,
- _from:null,
+cc.TintTo = cc.Class({
+ name: 'cc.TintTo',
+ extends: cc.ActionInterval,
ctor:function (duration, red, green, blue) {
- cc.ActionInterval.prototype.ctor.call(this);
this._to = cc.color(0, 0, 0);
this._from = cc.color(0, 0, 0);
@@ -2325,17 +2307,17 @@ cc.tintTo = function (duration, red, green, blue) {
* @example
* var action = new cc.TintBy(2, -127, -255, -127);
*/
-cc.TintBy = cc.ActionInterval.extend({
- _deltaR:0,
- _deltaG:0,
- _deltaB:0,
-
- _fromR:0,
- _fromG:0,
- _fromB:0,
+cc.TintBy = cc.Class({
+ name: 'cc.TintBy',
+ extends: cc.ActionInterval,
ctor:function (duration, deltaRed, deltaGreen, deltaBlue) {
- cc.ActionInterval.prototype.ctor.call(this);
+ this._deltaR = 0;
+ this._deltaG = 0;
+ this._deltaB = 0;
+ this._fromR = 0;
+ this._fromG = 0;
+ this._fromB = 0;
deltaBlue !== undefined && this.initWithDuration(duration, deltaRed, deltaGreen, deltaBlue);
},
@@ -2412,7 +2394,10 @@ cc.tintBy = function (duration, deltaRed, deltaGreen, deltaBlue) {
* @class DelayTime
* @extends ActionInterval
*/
-cc.DelayTime = cc.ActionInterval.extend({
+cc.DelayTime = cc.Class({
+ name: 'cc.DelayTime',
+ extends: cc.ActionInterval,
+
update:function (dt) {},
reverse:function () {
@@ -2457,13 +2442,12 @@ cc.delayTime = function (d) {
* @example
* var reverse = new cc.ReverseTime(this);
*/
-cc.ReverseTime = cc.ActionInterval.extend({
- _other:null,
+cc.ReverseTime = cc.Class({
+ name: 'cc.ReverseTime',
+ extends: cc.ActionInterval,
ctor:function (action) {
- cc.ActionInterval.prototype.ctor.call(this);
this._other = null;
-
action && this.initWithAction(action);
},
@@ -2527,176 +2511,6 @@ cc.reverseTime = function (action) {
return new cc.ReverseTime(action);
};
-/*
- * This API is deprecated, will be replaced by new API from {{#crossLink "Animation"}}cc.Animation{{/crossLink}}
- * Animates a sprite given the name of an Animation
- * @class Animate
- * @extends ActionInterval
- * @param {SpriteFrameAnimation} animation
- * @example
- * // create the animation with animation
- * var anim = new cc.Animate(dance_grey);
- */
-cc.Animate = cc.ActionInterval.extend({
- _animation:null,
- _nextFrame:0,
- _origFrame:null,
- _executedLoops:0,
- _splitTimes: null,
- _currFrameIndex:0,
-
- ctor:function (animation) {
- cc.ActionInterval.prototype.ctor.call(this);
- this._splitTimes = [];
-
- animation && this.initWithAnimation(animation);
- },
-
- /*
- * @return {SpriteFrameAnimation}
- */
- getAnimation:function () {
- return this._animation;
- },
-
- /*
- * @param {SpriteFrameAnimation} animation
- */
- setAnimation:function (animation) {
- this._animation = animation;
- },
-
- /*
- * Gets the index of sprite frame currently displayed.
- * @return {Number}
- */
- getCurrentFrameIndex: function () {
- return this._currFrameIndex;
- },
-
- /*
- * @param {SpriteFrameAnimation} animation
- * @return {Boolean}
- */
- initWithAnimation:function (animation) {
- if(!animation)
- throw new Error(cc._getError(1030));
- var singleDuration = animation.getDuration();
- if (this.initWithDuration(singleDuration * animation.getLoops())) {
- this._nextFrame = 0;
- this.setAnimation(animation);
-
- this._origFrame = null;
- this._executedLoops = 0;
- var locTimes = this._splitTimes;
- locTimes.length = 0;
-
- var accumUnitsOfTime = 0;
- var newUnitOfTimeValue = singleDuration / animation.getTotalDelayUnits();
-
- var frames = animation.getFrames();
- cc.js.array.verifyType(frames, cc.AnimationFrame);
-
- for (var i = 0; i < frames.length; i++) {
- var frame = frames[i];
- var value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
- accumUnitsOfTime += frame.getDelayUnits();
- locTimes.push(value);
- }
- return true;
- }
- return false;
- },
-
- clone:function () {
- var action = new cc.Animate();
- this._cloneDecoration(action);
- action.initWithAnimation(this._animation.clone());
- return action;
- },
-
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- if (this._animation.getRestoreOriginalFrame())
- this._origFrame = target.getSpriteFrame();
- this._nextFrame = 0;
- this._executedLoops = 0;
- },
-
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- // if t==1, ignore. Animation should finish with t==1
- if (dt < 1.0) {
- dt *= this._animation.getLoops();
-
- // new loop? If so, reset frame counter
- var loopNumber = 0 | dt;
- if (loopNumber > this._executedLoops) {
- this._nextFrame = 0;
- this._executedLoops++;
- }
-
- // new t for animations
- dt = dt % 1.0;
- }
-
- var frames = this._animation.getFrames();
- var numberOfFrames = frames.length, locSplitTimes = this._splitTimes;
- for (var i = this._nextFrame; i < numberOfFrames; i++) {
- if (locSplitTimes[i] <= dt) {
- _currFrameIndex = i;
- this.target.setSpriteFrame(frames[_currFrameIndex].getSpriteFrame());
- this._nextFrame = i + 1;
- } else {
- // Issue 1438. Could be more than one frame per tick, due to low frame rate or frame delta < 1/FPS
- break;
- }
- }
- },
-
- reverse:function () {
- var locAnimation = this._animation;
- var oldArray = locAnimation.getFrames();
- var newArray = [];
- cc.js.array.verifyType(oldArray, cc.AnimationFrame);
- if (oldArray.length > 0) {
- for (var i = oldArray.length - 1; i >= 0; i--) {
- var element = oldArray[i];
- if (!element)
- break;
- newArray.push(element.clone());
- }
- }
- var newAnim = new cc.SpriteFrameAnimation(newArray, locAnimation.getDelayPerUnit(), locAnimation.getLoops());
- newAnim.setRestoreOriginalFrame(locAnimation.getRestoreOriginalFrame());
- var action = new cc.Animate(newAnim);
- this._cloneDecoration(action);
- this._reverseEaseList(action);
-
- return action;
- },
-
- stop:function () {
- if (this._animation.getRestoreOriginalFrame() && this.target)
- this.target.setSpriteFrame(this._origFrame);
- cc.Action.prototype.stop.call(this);
- }
-});
-
-/*
- * create the animate with animation
- * @method animate
- * @param {SpriteFrameAnimation} animation
- * @return {ActionInterval}
- * @example
- * // example
- * // create the animation with animation
- * var anim = cc.animate(dance_grey);
- */
-cc.animate = function (animation) {
- return new cc.Animate(animation);
-};
-
/*
*
* Overrides the target of an action so that it always runs on the target
@@ -2707,12 +2521,13 @@ cc.animate = function (animation) {
* @param {Node} target
* @param {FiniteTimeAction} action
*/
-cc.TargetedAction = cc.ActionInterval.extend({
- _action:null,
- _forcedTarget:null,
+cc.TargetedAction = cc.Class({
+ name: 'cc.TargetedAction',
+ extends: cc.ActionInterval,
ctor: function (target, action) {
- cc.ActionInterval.prototype.ctor.call(this);
+ this._action = null;
+ this._forcedTarget = null;
action && this.initWithTarget(target, action);
},
diff --git a/cocos2d/actions/CCActionManager.js b/cocos2d/actions/CCActionManager.js
index 0d92bb2558..c0db024b13 100644
--- a/cocos2d/actions/CCActionManager.js
+++ b/cocos2d/actions/CCActionManager.js
@@ -24,6 +24,8 @@
THE SOFTWARE.
****************************************************************************/
+require('../core/platform/CCClass');
+
/*
* @class HashElement
* @constructor
@@ -57,8 +59,14 @@ var HashElement = function () {
* @class ActionManager
* @example {@link utils/api/engine/docs/cocos2d/core/CCActionManager/ActionManager.js}
*/
-cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{
-
+cc.ActionManager = function () {
+ this._hashTargets = {};
+ this._arrayTargets = [];
+ this._currentTarget = null;
+ this.__instanceId = cc.ClassManager.getNewInstanceId();
+};
+cc.ActionManager.prototype = {
+ constructor: cc.ActionManager,
_elementPool: [],
_searchElementByTarget:function (arr, target) {
@@ -69,12 +77,6 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{
return null;
},
- ctor:function () {
- this._hashTargets = {};
- this._arrayTargets = [];
- this._currentTarget = null;
- },
-
_getElement: function (target, paused) {
var element = this._elementPool.pop();
if (!element) {
@@ -436,7 +438,7 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{
}
}
}
-});
+};
if (CC_TEST) {
cc.ActionManager.prototype.isTargetPaused_TEST = function (target) {
diff --git a/cocos2d/core/CCConfiguration.js b/cocos2d/core/CCConfiguration.js
deleted file mode 100644
index c9b58841f2..0000000000
--- a/cocos2d/core/CCConfiguration.js
+++ /dev/null
@@ -1,283 +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.
- ****************************************************************************/
-
-/**
- * cc.configuration is a singleton object which contains some openGL variables
- * @class
- * @name cc.configuration
- * @example
- * var textureSize = cc.configuration.getMaxTextureSize();
- */
-cc.configuration = /** @lends cc.configuration# */{
- // Type constants
- /*
- * ERROR type
- * @public
- * @const
- * @type {Number}
- */
- ERROR:0,
-
- /*
- * STRING type
- * @public
- * @const
- * @type {Number}
- */
- STRING:1,
-
- /*
- * INT type
- * @public
- * @const
- * @type {Number}
- */
- INT:2,
-
- /*
- * DOUBLE type
- * @public
- * @const
- * @type {Number}
- */
- DOUBLE:3,
-
- /*
- * BOOLEAN type
- * @public
- * @const
- * @type {Number}
- */
- BOOLEAN:4,
-
- _maxTextureSize:0,
- _maxModelviewStackDepth:0,
- _supportsPVRTC:false,
- _supportsNPOT:false,
- _supportsBGRA8888:false,
- _supportsDiscardFramebuffer:false,
- _supportsShareableVAO:false,
- _maxSamplesAllowed:0,
- _maxTextureUnits:0,
- _GlExtensions:"",
- _valueDict:{},
-
- _inited: false,
-
- _init:function () {
- var locValueDict = this._valueDict;
- locValueDict["cocos2d.x.version"] = cc.ENGINE_VERSION;
- locValueDict["cocos2d.x.compiled_with_profiler"] = false;
- locValueDict["cocos2d.x.compiled_with_gl_state_cache"] = cc.macro.ENABLE_GL_STATE_CACHE;
- this._inited = true;
- },
-
- /**
- * OpenGL Max texture size.
- * @return {Number}
- */
- getMaxTextureSize:function () {
- return this._maxTextureSize;
- },
-
- /**
- * OpenGL Max Modelview Stack Depth.
- * @return {Number}
- */
- getMaxModelviewStackDepth:function () {
- return this._maxModelviewStackDepth;
- },
-
- /**
- * returns the maximum texture units
- * @return {Number}
- */
- getMaxTextureUnits:function () {
- return this._maxTextureUnits;
- },
-
- /**
- * Whether or not the GPU supports NPOT (Non Power Of Two) textures.
- * OpenGL ES 2.0 already supports NPOT (iOS).
- * @return {Boolean}
- */
- supportsNPOT:function () {
- return this._supportsNPOT;
- },
-
- /**
- * Whether or not PVR Texture Compressed is supported
- * @return {Boolean}
- */
- supportsPVRTC: function () {
- return this._supportsPVRTC;
- },
-
- /**
- * Whether or not ETC Texture Compressed is supported
- * @return {Boolean}
- */
- supportsETC: function() {
- return false;
- },
-
- /**
- * Whether or not S3TC Texture Compressed is supported
- * @return {Boolean}
- */
- supportsS3TC: function() {
- return false;
- },
-
- /**
- * Whether or not ATITC Texture Compressed is supported
- * @return {Boolean}
- */
- supportsATITC: function() {
- return false;
- },
-
- /**
- * Whether or not BGRA8888 textures are supported.
- * @return {Boolean}
- */
- supportsBGRA8888:function () {
- return this._supportsBGRA8888;
- },
-
- /**
- * Whether or not glDiscardFramebufferEXT is supported
- * @return {Boolean}
- */
- supportsDiscardFramebuffer:function () {
- return this._supportsDiscardFramebuffer;
- },
-
- /**
- * Whether or not shareable VAOs are supported.
- * @return {Boolean}
- */
- supportsShareableVAO:function () {
- return this._supportsShareableVAO;
- },
-
- /**
- * returns whether or not an OpenGL is supported
- * @param {String} searchName
- */
- checkForGLExtension:function (searchName) {
- return this._GlExtensions.indexOf(searchName) > -1;
- },
-
- /**
- * Returns the value of a given key. If the key is not found, it will return the default value
- * @param {String} key
- * @param {String|Bool|Number|Object} [default_value=null]
- * @returns {String|Bool|Number|Object}
- */
- getValue: function(key, default_value){
- if(!this._inited)
- this._init();
- var locValueDict = this._valueDict;
- if(locValueDict[key])
- return locValueDict[key];
- return default_value;
- },
-
- /**
- * Sets a new key/value pair in the configuration dictionary
- * @param {string} key
- * @param {String|Bool|Number|Object} value
- */
- setValue: function(key, value){
- this._valueDict[key] = value;
- },
-
- /**
- * gathers OpenGL / GPU information
- */
- gatherGPUInfo: function(){
- if(cc._renderType === cc.game.RENDER_TYPE_CANVAS)
- return;
-
- if(!this._inited)
- this._init();
- var gl = cc._renderContext;
- var locValueDict = this._valueDict;
- locValueDict["gl.vendor"] = gl.getParameter(gl.VENDOR);
- locValueDict["gl.renderer"] = gl.getParameter(gl.RENDERER);
- locValueDict["gl.version"] = gl.getParameter(gl.VERSION);
-
- this._GlExtensions = "";
- var extArr = gl.getSupportedExtensions();
- for (var i = 0; i < extArr.length; i++)
- this._GlExtensions += extArr[i] + " ";
-
- this._maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
- locValueDict["gl.max_texture_size"] = this._maxTextureSize;
- this._maxTextureUnits = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
- locValueDict["gl.max_texture_units"] = this._maxTextureUnits;
-
- this._supportsPVRTC = this.checkForGLExtension("GL_IMG_texture_compression_pvrtc");
- locValueDict["gl.supports_PVRTC"] = this._supportsPVRTC;
-
- this._supportsNPOT = false; //true;
- locValueDict["gl.supports_NPOT"] = this._supportsNPOT;
-
- this._supportsBGRA8888 = this.checkForGLExtension("GL_IMG_texture_format_BGRA888");
- locValueDict["gl.supports_BGRA8888"] = this._supportsBGRA8888;
-
- this._supportsDiscardFramebuffer = this.checkForGLExtension("GL_EXT_discard_framebuffer");
- locValueDict["gl.supports_discard_framebuffer"] = this._supportsDiscardFramebuffer;
-
- this._supportsShareableVAO = this.checkForGLExtension("vertex_array_object");
- locValueDict["gl.supports_vertex_array_object"] = this._supportsShareableVAO;
-
- cc.checkGLErrorDebug();
- },
-
- /**
- * Loads a config file. If the keys are already present, then they are going to be replaced. Otherwise the new keys are added.
- * @param {string} url
- */
- loadConfigFile: function( url){
- if(!this._inited)
- this._init();
- var dict = cc.loader.getRes(url);
- if(!dict) throw new Error(cc._getError(1102, url));
- cc.assertID(dict, 1101, url);
-
- var getDatas = dict["data"];
- if(!getDatas){
- cc.logID(1100, url);
- return;
- }
-
- // Add all keys in the existing dictionary
- for(var selKey in getDatas)
- this._valueDict[selKey] = getDatas[selKey];
- }
-};
\ No newline at end of file
diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js
index 435dd2274b..7ed10fc4c8 100644
--- a/cocos2d/core/CCDirector.js
+++ b/cocos2d/core/CCDirector.js
@@ -25,7 +25,6 @@
****************************************************************************/
const EventTarget = require('./event/event-target');
-const Class = require('./platform/_CCClass');
const AutoReleaseUtils = require('./load-pipeline/auto-release-utils');
const ComponentScheduler = require('./component-scheduler');
const NodeActivator = require('./node-activator');
@@ -103,43 +102,45 @@ const eventManager = require('./event-manager');
* @class Director
* @extends EventTarget
*/
-cc.Director = Class.extend(/** @lends cc.Director# */{
- ctor: function () {
- var self = this;
- EventTarget.call(self);
+cc.Director = function () {
+ EventTarget.call(this);
- // paused?
- self._paused = false;
- // purge?
- self._purgeDirectorInNextLoop = false;
- self._animationInterval = 0.0;
- self._oldAnimationInterval = 0.0;
+ this.invalid = false;
+ // paused?
+ this._paused = false;
+ // purge?
+ this._purgeDirectorInNextLoop = false;
+ this._animationInterval = 0.0;
+ this._oldAnimationInterval = 0.0;
- self._winSizeInPoints = null;
+ this._winSizeInPoints = null;
- // scenes
- self._loadingScene = '';
- self._scene = null;
+ // scenes
+ this._loadingScene = '';
+ this._scene = null;
- // FPS
- self._totalFrames = 0;
+ // FPS
+ this._totalFrames = 0;
+ this._lastUpdate = Date.now();
+ this._deltaTime = 0.0;
+
+ // Scheduler for user registration update
+ this._scheduler = null;
+ // Scheduler for life-cycle methods in component
+ this._compScheduler = null;
+ // Node activator
+ this._nodeActivator = null;
+ // Action manager
+ this._actionManager = null;
+
+ var self = this;
+ cc.game.on(cc.game.EVENT_SHOW, function () {
self._lastUpdate = Date.now();
- self._deltaTime = 0.0;
-
- // Scheduler for user registration update
- self._scheduler = null;
- // Scheduler for life-cycle methods in component
- self._compScheduler = null;
- // Node activator
- self._nodeActivator = null;
- // Action manager
- self._actionManager = null;
-
- cc.game.on(cc.game.EVENT_SHOW, function () {
- self._lastUpdate = Date.now();
- });
- },
+ });
+};
+cc.Director.prototype = {
+ constructor: cc.Director,
init: function () {
this._oldAnimationInterval = this._animationInterval = 1.0 / cc.defaultFPS;
@@ -161,7 +162,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
return true;
},
- /**
+ /*
* Manage all init process shared between the web engine and jsb engine.
* All platform independent init process should be occupied here.
*/
@@ -836,7 +837,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
* @deprecated
*/
getRunningScene: function () {
- return null;
+ return this._scene;
},
/**
@@ -989,7 +990,120 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
getPhysicsManager: function () {
return this._physicsManager;
},
-});
+
+ // Loop management
+ /*
+ * Starts Animation
+ */
+ startAnimation: function () {
+ this.invalid = false;
+ this._lastUpdate = Date.now();
+ },
+
+ /*
+ * Stops animation
+ */
+ stopAnimation: function () {
+ this.invalid = true;
+ },
+
+ /*
+ * Run main loop of director
+ */
+ mainLoop: CC_EDITOR ? function (deltaTime, updateAnimate) {
+ if (!this._paused) {
+ this.emit(cc.Director.EVENT_BEFORE_UPDATE);
+
+ this._compScheduler.startPhase();
+ this._compScheduler.updatePhase(deltaTime);
+
+ if (updateAnimate) {
+ this._scheduler.update(deltaTime);
+ }
+
+ this._compScheduler.lateUpdatePhase(deltaTime);
+
+ this.emit(cc.Director.EVENT_AFTER_UPDATE);
+ }
+
+ this.emit(cc.Director.EVENT_BEFORE_VISIT);
+ // update the scene
+ this.emit(cc.Director.EVENT_AFTER_VISIT);
+
+ // Render
+ renderer.render(this._scene);
+ this._totalFrames++;
+
+ this.emit(cc.Director.EVENT_AFTER_DRAW);
+
+ } : function () {
+ if (this._purgeDirectorInNextLoop) {
+ this._purgeDirectorInNextLoop = false;
+ this.purgeDirector();
+ }
+ else if (!this.invalid) {
+ // calculate "global" dt
+ this.calculateDeltaTime();
+
+ if (!this._paused) {
+ this.emit(cc.Director.EVENT_BEFORE_UPDATE);
+ // Call start for new added components
+ this._compScheduler.startPhase();
+ // Update for components
+ this._compScheduler.updatePhase(this._deltaTime);
+ // Engine update with scheduler
+ this._scheduler.update(this._deltaTime);
+ // Late update for components
+ this._compScheduler.lateUpdatePhase(this._deltaTime);
+ // User can use this event to do things after update
+ this.emit(cc.Director.EVENT_AFTER_UPDATE);
+ // Destroy entities that have been removed recently
+ cc.Object._deferredDestroy();
+ }
+ this.emit(cc.Director.EVENT_BEFORE_VISIT);
+ // update the scene
+ this.emit(cc.Director.EVENT_AFTER_VISIT);
+
+ // Render
+ renderer.render(this._scene);
+ this._totalFrames++;
+
+ this.emit(cc.Director.EVENT_AFTER_DRAW);
+ eventManager.frameUpdateListeners();
+ }
+ },
+
+ /**
+ * Sets animation interval, this doesn't control the main loop.
+ * To control the game's frame rate overall, please use {{#crossLink "Game.setFrameRate"}}cc.game.setFrameRate{{/crossLink}}
+ * @method setAnimationInterval
+ * @param {Number} value - The animation interval desired.
+ */
+ setAnimationInterval: function (value) {
+ this._animationInterval = value;
+ if (!this.invalid) {
+ this.stopAnimation();
+ this.startAnimation();
+ }
+ },
+
+ __fastOn: function (type, callback, target) {
+ var listeners = this._bubblingListeners;
+ if (!listeners) {
+ listeners = this._bubblingListeners = new EventListeners();
+ }
+ listeners.add(type, callback, target);
+ this._addEventFlag(type, listeners, false);
+ },
+
+ __fastOff: function (type, callback, target) {
+ var listeners = this._bubblingListeners;
+ if (listeners) {
+ listeners.remove(type, callback, target);
+ this._purgeEventFlag(type, listeners, false);
+ }
+ },
+};
// Event target
cc.js.addon(cc.Director.prototype, EventTarget.prototype);
@@ -1133,132 +1247,13 @@ cc.Director.EVENT_AFTER_VISIT = "director_after_visit";
*/
cc.Director.EVENT_AFTER_DRAW = "director_after_draw";
-/***************************************************
- * implementation of DisplayLinkDirector
- **************************************************/
-
-cc.DisplayLinkDirector = cc.Director.extend(/** @lends cc.Director# */{
- invalid: false,
-
- /**
- * Starts Animation
- */
- startAnimation: function () {
- this.invalid = false;
- this._lastUpdate = Date.now();
- },
-
- /**
- * Run main loop of director
- */
- mainLoop: CC_EDITOR ? function (deltaTime, updateAnimate) {
- if (!this._paused) {
- this.emit(cc.Director.EVENT_BEFORE_UPDATE);
-
- this._compScheduler.startPhase();
- this._compScheduler.updatePhase(deltaTime);
-
- if (updateAnimate) {
- this._scheduler.update(deltaTime);
- }
-
- this._compScheduler.lateUpdatePhase(deltaTime);
-
- this.emit(cc.Director.EVENT_AFTER_UPDATE);
- }
-
- this.emit(cc.Director.EVENT_BEFORE_VISIT);
- // update the scene
- this.emit(cc.Director.EVENT_AFTER_VISIT);
-
- // Render
- renderer.render(this._scene);
- this._totalFrames++;
-
- this.emit(cc.Director.EVENT_AFTER_DRAW);
-
- } : function () {
- if (this._purgeDirectorInNextLoop) {
- this._purgeDirectorInNextLoop = false;
- this.purgeDirector();
- }
- else if (!this.invalid) {
- // calculate "global" dt
- this.calculateDeltaTime();
-
- if (!this._paused) {
- this.emit(cc.Director.EVENT_BEFORE_UPDATE);
- // Call start for new added components
- this._compScheduler.startPhase();
- // Update for components
- this._compScheduler.updatePhase(this._deltaTime);
- // Engine update with scheduler
- this._scheduler.update(this._deltaTime);
- // Late update for components
- this._compScheduler.lateUpdatePhase(this._deltaTime);
- // User can use this event to do things after update
- this.emit(cc.Director.EVENT_AFTER_UPDATE);
- // Destroy entities that have been removed recently
- cc.Object._deferredDestroy();
- }
- this.emit(cc.Director.EVENT_BEFORE_VISIT);
- // update the scene
- this.emit(cc.Director.EVENT_AFTER_VISIT);
-
- // Render
- renderer.render(this._scene);
- this._totalFrames++;
-
- this.emit(cc.Director.EVENT_AFTER_DRAW);
- eventManager.frameUpdateListeners();
- }
- },
-
- /**
- * Stops animation
- */
- stopAnimation: function () {
- this.invalid = true;
- },
-
- /**
- * Sets animation interval, this doesn't control the main loop.
- * To control the game's frame rate overall, please use {{#crossLink "Game.setFrameRate"}}cc.game.setFrameRate{{/crossLink}}
- * @param {Number} value - The animation interval desired.
- */
- setAnimationInterval: function (value) {
- this._animationInterval = value;
- if (!this.invalid) {
- this.stopAnimation();
- this.startAnimation();
- }
- },
-
- __fastOn: function (type, callback, target) {
- var listeners = this._bubblingListeners;
- if (!listeners) {
- listeners = this._bubblingListeners = new EventListeners();
- }
- listeners.add(type, callback, target);
- this._addEventFlag(type, listeners, false);
- },
-
- __fastOff: function (type, callback, target) {
- var listeners = this._bubblingListeners;
- if (listeners) {
- listeners.remove(type, callback, target);
- this._purgeEventFlag(type, listeners, false);
- }
- },
-});
-
cc.Director.sharedDirector = null;
cc.Director.firstUseDirector = true;
cc.Director._getInstance = function () {
if (cc.Director.firstUseDirector) {
cc.Director.firstUseDirector = false;
- cc.Director.sharedDirector = new cc.DisplayLinkDirector();
+ cc.Director.sharedDirector = new cc.Director();
cc.Director.sharedDirector.init();
}
return cc.Director.sharedDirector;
diff --git a/cocos2d/core/CCScheduler.js b/cocos2d/core/CCScheduler.js
index f0985028d7..8b963b7720 100644
--- a/cocos2d/core/CCScheduler.js
+++ b/cocos2d/core/CCScheduler.js
@@ -280,23 +280,23 @@ var getTargetId = function (target) {
*
* @class Scheduler
*/
-cc.Scheduler = cc._Class.extend({
+cc.Scheduler = function () {
+ this._timeScale = 1.0;
+ this._updatesNegList = []; // list of priority < 0
+ this._updates0List = []; // list of priority == 0
+ this._updatesPosList = []; // list of priority > 0
+ this._hashForUpdates = {}; // hash used to fetch quickly the list entries for pause, delete, etc
+ this._hashForTimers = {}; // Used for "selectors with interval"
+ this._currentTarget = null;
+ this._currentTargetSalvaged = false;
+ this._updateHashLocked = false; // If true unschedule will not remove anything from a hash. Elements will only be marked for deletion.
- ctor: function () {
- this._timeScale = 1.0;
- this._updatesNegList = []; // list of priority < 0
- this._updates0List = []; // list of priority == 0
- this._updatesPosList = []; // list of priority > 0
- this._hashForUpdates = {}; // hash used to fetch quickly the list entries for pause, delete, etc
- this._hashForTimers = {}; // Used for "selectors with interval"
- this._currentTarget = null;
- this._currentTargetSalvaged = false;
- this._updateHashLocked = false; // If true unschedule will not remove anything from a hash. Elements will only be marked for deletion.
-
- this._arrayForTimers = []; // Speed up indexing
- //this._arrayForUpdates = []; // Speed up indexing
- },
+ this._arrayForTimers = []; // Speed up indexing
+ //this._arrayForUpdates = []; // Speed up indexing
+};
+cc.Scheduler.prototype = {
+ constructor: cc.Scheduler,
//-----------------------private method----------------------
_removeHashElement: function (element) {
@@ -1113,7 +1113,7 @@ cc.Scheduler = cc._Class.extend({
//cc.log("unscheduleAllCallbacksWithMinPriority is deprecated. Please use unscheduleAllWithMinPriority.");
this.unscheduleAllWithMinPriority(minPriority);
}
-});
+};
/**
* !#en Priority level reserved for system services.
diff --git a/cocos2d/core/components/CCRichText.js b/cocos2d/core/components/CCRichText.js
index 587f78ede7..915de1a685 100644
--- a/cocos2d/core/components/CCRichText.js
+++ b/cocos2d/core/components/CCRichText.js
@@ -22,8 +22,11 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
-require('../label/CCHtmlTextParser');
-require('../label/CCTextUtils');
+
+var utils = require('../utils/text-utils');
+var HtmlTextParser = utils.HtmlTextParser;
+var TextUtils = utils.TextUtils;
+var CustomFontLoader = utils.CustomFontLoader;
var JS = require("../platform/js");
@@ -31,7 +34,7 @@ var HorizontalAlign = cc.TextAlignment;
var VerticalAlign = cc.VerticalTextAlignment;
var RichTextChildName = "RICHTEXT_CHILD"
var RichTextChildZIndex = - 1000000;
-
+var _htmlTextParser = new HtmlTextParser();
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
@@ -337,7 +340,7 @@ var RichText = cc.Class({
self._updateRichText();
};
- cc.CustomFontLoader.loadTTF(rawUrl, callback);
+ CustomFontLoader.loadTTF(rawUrl, callback);
},
_measureText: function (styleIndex, string) {
@@ -471,7 +474,7 @@ var RichText = cc.Class({
}
}
if (fragmentWidth > this.maxWidth) {
- var fragments = cc.TextUtils.fragmentText(labelString,
+ var fragments = TextUtils.fragmentText(labelString,
fragmentWidth,
this.maxWidth,
this._measureText(styleIndex));
@@ -616,7 +619,7 @@ var RichText = cc.Class({
_updateRichText: function () {
if (!this.enabled) return;
- var newTextArray = cc.htmlTextParser.parse(this.string);
+ var newTextArray = _htmlTextParser.parse(this.string);
if (!this._needsUpdateTextLayout(newTextArray)) {
this._textArray = newTextArray;
this._updateLabelSegmentTextAttributes();
@@ -701,16 +704,16 @@ var RichText = cc.Class({
_getFirstWordLen: function (text, startIndex, textLen) {
var character = text.charAt(startIndex);
- if (cc.TextUtils.isUnicodeCJK(character)
- || cc.TextUtils.isUnicodeSpace(character)) {
+ if (TextUtils.isUnicodeCJK(character)
+ || TextUtils.isUnicodeSpace(character)) {
return 1;
}
var len = 1;
for (var index = startIndex + 1; index < textLen; ++index) {
character = text.charAt(index);
- if (cc.TextUtils.isUnicodeSpace(character)
- || cc.TextUtils.isUnicodeCJK(character)) {
+ if (TextUtils.isUnicodeSpace(character)
+ || TextUtils.isUnicodeCJK(character)) {
break;
}
len++;
diff --git a/cocos2d/core/event-manager/CCEventListener.js b/cocos2d/core/event-manager/CCEventListener.js
index 4da7586717..32289b70c8 100644
--- a/cocos2d/core/event-manager/CCEventListener.js
+++ b/cocos2d/core/event-manager/CCEventListener.js
@@ -22,6 +22,9 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
+
+var js = require('../platform/js');
+
/**
* !#en
*
@@ -45,26 +48,21 @@ * @param {Number} listenerID * @param {Number} callback */ -cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{ - /* - * Initializes event with type and callback function. - * @param {Number} type - * @param {String} listenerID - * @param {Function} callback - */ - ctor: function (type, listenerID, callback) { - this._onEvent = callback; // Event callback function - this._type = type || 0; // Event listener type - this._listenerID = listenerID || ""; // Event listener ID - this._registered = false; // Whether the listener has been added to dispatcher. +cc.EventListener = function (type, listenerID, callback) { + this._onEvent = callback; // Event callback function + this._type = type || 0; // Event listener type + this._listenerID = listenerID || ""; // Event listener ID + this._registered = false; // Whether the listener has been added to dispatcher. - this._fixedPriority = 0; // The higher the number, the higher the priority, 0 is for scene graph base priority. - this._node = null; // scene graph based priority - this._target = null; - this._paused = true; // Whether the listener is paused - this._isEnabled = true; // Whether the listener is enabled - }, + this._fixedPriority = 0; // The higher the number, the higher the priority, 0 is for scene graph base priority. + this._node = null; // scene graph based priority + this._target = null; + this._paused = true; // Whether the listener is paused + this._isEnabled = true; // Whether the listener is enabled +}; +cc.EventListener.prototype = { + constructor: cc.EventListener, /* *
* Sets paused state for the listener @@ -243,7 +241,7 @@ cc.EventListener = cc._Class.extend(/** @lends cc.EventListener# */{ */ release:function () { } -}); +}; // event listener type /** @@ -303,13 +301,22 @@ cc.EventListener.ACCELERATION = 6; */ cc.EventListener.CUSTOM = 8; -cc._EventListenerCustom = cc.EventListener.extend({ - _onCustomEvent: null, - ctor: function (listenerId, callback) { - this._onCustomEvent = callback; - cc.EventListener.prototype.ctor.call(this, cc.EventListener.CUSTOM, listenerId, this._callback); - }, +var ListenerID = cc.EventListener.ListenerID = { + MOUSE: '__cc_mouse', + TOUCH_ONE_BY_ONE: '__cc_touch_one_by_one', + TOUCH_ALL_AT_ONCE: '__cc_touch_all_at_once', + KEYBOARD: '__cc_keyboard', + ACCELERATION: '__cc_acceleration', +}; +var Custom = function (listenerId, callback) { + this._onCustomEvent = callback; + cc.EventListener.prototype.ctor.call(this, cc.EventListener.CUSTOM, listenerId, this._callback); +}; +js.extend(Custom, cc.EventListener); +js.addon(Custom.prototype, { + _onCustomEvent: null, + _callback: function (event) { if (this._onCustomEvent !== null) this._onCustomEvent(event); @@ -320,20 +327,20 @@ cc._EventListenerCustom = cc.EventListener.extend({ }, clone: function () { - return new cc._EventListenerCustom(this._listenerID, this._onCustomEvent); + return new Custom(this._listenerID, this._onCustomEvent); } }); -cc._EventListenerMouse = cc.EventListener.extend({ +var Mouse = function () { + cc.EventListener.prototype.ctor.call(this, cc.EventListener.MOUSE, ListenerID.MOUSE, this._callback); +}; +js.extend(Mouse, cc.EventListener); +js.addon(Mouse.prototype, { onMouseDown: null, onMouseUp: null, onMouseMove: null, onMouseScroll: null, - ctor: function () { - cc.EventListener.prototype.ctor.call(this, cc.EventListener.MOUSE, cc._EventListenerMouse.LISTENER_ID, this._callback); - }, - _callback: function (event) { var eventType = cc.Event.EventMouse; switch (event._eventType) { @@ -359,7 +366,7 @@ cc._EventListenerMouse = cc.EventListener.extend({ }, clone: function () { - var eventListener = new cc._EventListenerMouse(); + var eventListener = new Mouse(); eventListener.onMouseDown = this.onMouseDown; eventListener.onMouseUp = this.onMouseUp; eventListener.onMouseMove = this.onMouseMove; @@ -372,9 +379,13 @@ cc._EventListenerMouse = cc.EventListener.extend({ } }); -cc._EventListenerMouse.LISTENER_ID = "__cc_mouse"; - -cc._EventListenerTouchOneByOne = cc.EventListener.extend({ +var TouchOneByOne = function () { + cc.EventListener.prototype.ctor.call(this, cc.EventListener.TOUCH_ONE_BY_ONE, ListenerID.TOUCH_ONE_BY_ONE, null); + this._claimedTouches = []; +}; +js.extend(TouchOneByOne, cc.EventListener); +js.addon(TouchOneByOne.prototype, { + constructor: TouchOneByOne, _claimedTouches: null, swallowTouches: false, onTouchBegan: null, @@ -382,11 +393,6 @@ cc._EventListenerTouchOneByOne = cc.EventListener.extend({ onTouchEnded: null, onTouchCancelled: null, - ctor: function () { - cc.EventListener.prototype.ctor.call(this, cc.EventListener.TOUCH_ONE_BY_ONE, cc._EventListenerTouchOneByOne.LISTENER_ID, null); - this._claimedTouches = []; - }, - setSwallowTouches: function (needSwallow) { this.swallowTouches = needSwallow; }, @@ -396,7 +402,7 @@ cc._EventListenerTouchOneByOne = cc.EventListener.extend({ }, clone: function () { - var eventListener = new cc._EventListenerTouchOneByOne(); + var eventListener = new TouchOneByOne(); eventListener.onTouchBegan = this.onTouchBegan; eventListener.onTouchMoved = this.onTouchMoved; eventListener.onTouchEnded = this.onTouchEnded; @@ -414,20 +420,19 @@ cc._EventListenerTouchOneByOne = cc.EventListener.extend({ } }); -cc._EventListenerTouchOneByOne.LISTENER_ID = "__cc_touch_one_by_one"; - -cc._EventListenerTouchAllAtOnce = cc.EventListener.extend({ +var TouchAllAtOnce = function () { + cc.EventListener.prototype.ctor.call(this, cc.EventListener.TOUCH_ALL_AT_ONCE, ListenerID.TOUCH_ALL_AT_ONCE, null); +}; +js.extend(TouchAllAtOnce, cc.EventListener); +js.addon(TouchAllAtOnce.prototype, { + constructor: TouchAllAtOnce, onTouchesBegan: null, onTouchesMoved: null, onTouchesEnded: null, onTouchesCancelled: null, - ctor: function(){ - cc.EventListener.prototype.ctor.call(this, cc.EventListener.TOUCH_ALL_AT_ONCE, cc._EventListenerTouchAllAtOnce.LISTENER_ID, null); - }, - clone: function(){ - var eventListener = new cc._EventListenerTouchAllAtOnce(); + var eventListener = new TouchAllAtOnce(); eventListener.onTouchesBegan = this.onTouchesBegan; eventListener.onTouchesMoved = this.onTouchesMoved; eventListener.onTouchesEnded = this.onTouchesEnded; @@ -445,62 +450,16 @@ cc._EventListenerTouchAllAtOnce = cc.EventListener.extend({ } }); -cc._EventListenerTouchAllAtOnce.LISTENER_ID = "__cc_touch_all_at_once"; - -/** - * !#en - * Create a EventListener object with configuration including the event type, handlers and other parameters. - * In handlers, this refer to the event listener object itself. - * You can also pass custom parameters in the configuration object, - * all custom parameters will be polyfilled into the event listener object and can be accessed in handlers. - * !#zh 通过指定不同的 Event 对象来设置想要创建的事件监听器。 - * @method create - * @param {Object} argObj a json object - * @returns {EventListener} - * @static - * @example {@link utils/api/engine/docs/cocos2d/core/event-manager/CCEventListener/create.js} - */ -cc.EventListener.create = function(argObj){ - - cc.assertID(argObj&&argObj.event, 1900); - - var listenerType = argObj.event; - delete argObj.event; - - var listener = null; - if(listenerType === cc.EventListener.TOUCH_ONE_BY_ONE) - listener = new cc._EventListenerTouchOneByOne(); - else if(listenerType === cc.EventListener.TOUCH_ALL_AT_ONCE) - listener = new cc._EventListenerTouchAllAtOnce(); - else if(listenerType === cc.EventListener.MOUSE) - listener = new cc._EventListenerMouse(); - else if(listenerType === cc.EventListener.CUSTOM){ - listener = new cc._EventListenerCustom(argObj.eventName, argObj.callback); - delete argObj.eventName; - delete argObj.callback; - } else if(listenerType === cc.EventListener.KEYBOARD) - listener = new cc._EventListenerKeyboard(); - else if(listenerType === cc.EventListener.ACCELERATION){ - listener = new cc._EventListenerAcceleration(argObj.callback); - delete argObj.callback; - } - - for(var key in argObj) { - listener[key] = argObj[key]; - } - - return listener; -}; - //Acceleration -cc._EventListenerAcceleration = cc.EventListener.extend({ +var Acceleration = function (callback) { + this._onAccelerationEvent = callback; + cc.EventListener.prototype.ctor.call(this, cc.EventListener.ACCELERATION, ListenerID.ACCELERATION, this._callback); +}; +js.extend(Acceleration, cc.EventListener); +js.addon(Acceleration.prototype, { + constructor: Acceleration, _onAccelerationEvent: null, - ctor: function (callback) { - this._onAccelerationEvent = callback; - cc.EventListener.prototype.ctor.call(this, cc.EventListener.ACCELERATION, cc._EventListenerAcceleration.LISTENER_ID, this._callback); - }, - _callback: function (event) { this._onAccelerationEvent(event.acc, event); }, @@ -512,22 +471,21 @@ cc._EventListenerAcceleration = cc.EventListener.extend({ }, clone: function () { - return new cc._EventListenerAcceleration(this._onAccelerationEvent); + return new Acceleration(this._onAccelerationEvent); } }); -cc._EventListenerAcceleration.LISTENER_ID = "__cc_acceleration"; - //Keyboard -cc._EventListenerKeyboard = cc.EventListener.extend({ +var Keyboard = function () { + cc.EventListener.prototype.ctor.call(this, cc.EventListener.KEYBOARD, ListenerID.KEYBOARD, this._callback); +}; +js.extend(Keyboard, cc.EventListener); +js.addon(Keyboard.prototype, { + constructor: Keyboard, onKeyPressed: null, onKeyReleased: null, - ctor: function () { - cc.EventListener.prototype.ctor.call(this, cc.EventListener.KEYBOARD, cc._EventListenerKeyboard.LISTENER_ID, this._callback); - }, - _callback: function (event) { if (event.isPressed) { if (this.onKeyPressed) @@ -539,7 +497,7 @@ cc._EventListenerKeyboard = cc.EventListener.extend({ }, clone: function () { - var eventListener = new cc._EventListenerKeyboard(); + var eventListener = new Keyboard(); eventListener.onKeyPressed = this.onKeyPressed; eventListener.onKeyReleased = this.onKeyReleased; return eventListener; @@ -554,4 +512,47 @@ cc._EventListenerKeyboard = cc.EventListener.extend({ } }); -cc._EventListenerKeyboard.LISTENER_ID = "__cc_keyboard"; \ No newline at end of file +/** + * !#en + * Create a EventListener object with configuration including the event type, handlers and other parameters. + * In handlers, this refer to the event listener object itself. + * You can also pass custom parameters in the configuration object, + * all custom parameters will be polyfilled into the event listener object and can be accessed in handlers. + * !#zh 通过指定不同的 Event 对象来设置想要创建的事件监听器。 + * @method create + * @param {Object} argObj a json object + * @returns {EventListener} + * @static + * @example {@link utils/api/engine/docs/cocos2d/core/event-manager/CCEventListener/create.js} + */ +cc.EventListener.create = function (argObj) { + cc.assertID(argObj&&argObj.event, 1900); + + var listenerType = argObj.event; + delete argObj.event; + + var listener = null; + if(listenerType === cc.EventListener.TOUCH_ONE_BY_ONE) + listener = new TouchOneByOne(); + else if(listenerType === cc.EventListener.TOUCH_ALL_AT_ONCE) + listener = new TouchAllAtOnce(); + else if(listenerType === cc.EventListener.MOUSE) + listener = new Mouse(); + else if(listenerType === cc.EventListener.CUSTOM){ + listener = new Custom(argObj.eventName, argObj.callback); + delete argObj.eventName; + delete argObj.callback; + } else if(listenerType === cc.EventListener.KEYBOARD) + listener = new Keyboard(); + else if(listenerType === cc.EventListener.ACCELERATION){ + listener = new Acceleration(argObj.callback); + delete argObj.callback; + } + + for(var key in argObj) { + listener[key] = argObj[key]; + } + return listener; +}; + +module.exports = cc.EventListener; \ No newline at end of file diff --git a/cocos2d/core/event-manager/CCEventManager.js b/cocos2d/core/event-manager/CCEventManager.js index e920dadc08..a9639211a1 100644 --- a/cocos2d/core/event-manager/CCEventManager.js +++ b/cocos2d/core/event-manager/CCEventManager.js @@ -23,15 +23,16 @@ THE SOFTWARE. ****************************************************************************/ var js = require('../platform/js'); +require('./CCEventListener'); +var ListenerID = cc.EventListener.ListenerID; -var _EventListenerVector = cc._Class.extend({ - - ctor: function () { - this._fixedListeners = []; - this._sceneGraphListeners = []; - this.gt0Index = 0; - }, - +var _EventListenerVector = function () { + this._fixedListeners = []; + this._sceneGraphListeners = []; + this.gt0Index = 0; +}; +_EventListenerVector.prototype = { + constructor: _EventListenerVector, size: function () { return this._fixedListeners.length + this._sceneGraphListeners.length; }, @@ -67,16 +68,16 @@ var _EventListenerVector = cc._Class.extend({ getSceneGraphPriorityListeners: function () { return this._sceneGraphListeners; } -}); +}; var __getListenerID = function (event) { var eventType = cc.Event, type = event.type; if (type === eventType.ACCELERATION) - return cc._EventListenerAcceleration.LISTENER_ID; + return ListenerID.ACCELERATION; if (type === eventType.KEYBOARD) - return cc._EventListenerKeyboard.LISTENER_ID; + return ListenerID.KEYBOARD; if (type.startsWith(eventType.MOUSE)) - return cc._EventListenerMouse.LISTENER_ID; + return ListenerID.MOUSE; if (type.startsWith(eventType.TOUCH)){ // Touch listener is very special, it contains two kinds of listeners, EventListenerTouchOneByOne and EventListenerTouchAllAtOnce. // return UNKNOWN instead. @@ -428,11 +429,11 @@ var eventManager = { return; var listeners; - listeners = this._listenersMap[cc._EventListenerTouchOneByOne.LISTENER_ID]; + listeners = this._listenersMap[ListenerID.TOUCH_ONE_BY_ONE]; if (listeners) { this._onUpdateListeners(listeners); } - listeners = this._listenersMap[cc._EventListenerTouchAllAtOnce.LISTENER_ID]; + listeners = this._listenersMap[ListenerID.TOUCH_ALL_AT_ONCE]; if (listeners) { this._onUpdateListeners(listeners); } @@ -528,11 +529,11 @@ var eventManager = { }, _dispatchTouchEvent: function (event) { - this._sortEventListeners(cc._EventListenerTouchOneByOne.LISTENER_ID); - this._sortEventListeners(cc._EventListenerTouchAllAtOnce.LISTENER_ID); + this._sortEventListeners(ListenerID.TOUCH_ONE_BY_ONE); + this._sortEventListeners(ListenerID.TOUCH_ALL_AT_ONCE); - var oneByOneListeners = this._getListeners(cc._EventListenerTouchOneByOne.LISTENER_ID); - var allAtOnceListeners = this._getListeners(cc._EventListenerTouchAllAtOnce.LISTENER_ID); + var oneByOneListeners = this._getListeners(ListenerID.TOUCH_ONE_BY_ONE); + var allAtOnceListeners = this._getListeners(ListenerID.TOUCH_ALL_AT_ONCE); // If there aren't any touch listeners, return directly. if (null === oneByOneListeners && null === allAtOnceListeners) @@ -785,7 +786,11 @@ var eventManager = { * @return {EventListener} the generated event. Needed in order to remove the event from the dispatcher */ addCustomListener: function (eventName, callback) { - var listener = new cc._EventListenerCustom(eventName, callback); + var listener = new cc.EventListener.create({ + event: cc.EventListener.CUSTOM, + eventName: eventName, + callback: callback + }); this.addListener(listener, 1); return listener; }, @@ -944,15 +949,15 @@ var eventManager = { } } else { if (listenerType === cc.EventListener.TOUCH_ONE_BY_ONE) - _t._removeListenersForListenerID(cc._EventListenerTouchOneByOne.LISTENER_ID); + _t._removeListenersForListenerID(ListenerID.TOUCH_ONE_BY_ONE); else if (listenerType === cc.EventListener.TOUCH_ALL_AT_ONCE) - _t._removeListenersForListenerID(cc._EventListenerTouchAllAtOnce.LISTENER_ID); + _t._removeListenersForListenerID(ListenerID.TOUCH_ALL_AT_ONCE); else if (listenerType === cc.EventListener.MOUSE) - _t._removeListenersForListenerID(cc._EventListenerMouse.LISTENER_ID); + _t._removeListenersForListenerID(ListenerID.MOUSE); else if (listenerType === cc.EventListener.ACCELERATION) - _t._removeListenersForListenerID(cc._EventListenerAcceleration.LISTENER_ID); + _t._removeListenersForListenerID(ListenerID.ACCELERATION); else if (listenerType === cc.EventListener.KEYBOARD) - _t._removeListenersForListenerID(cc._EventListenerKeyboard.LISTENER_ID); + _t._removeListenersForListenerID(ListenerID.KEYBOARD); else cc.logID(3501); } diff --git a/cocos2d/core/event-manager/CCTouch.js b/cocos2d/core/event-manager/CCTouch.js index d052c0228c..817216d607 100644 --- a/cocos2d/core/event-manager/CCTouch.js +++ b/cocos2d/core/event-manager/CCTouch.js @@ -32,13 +32,12 @@ * @param {Number} y * @param {Number} id */ -cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{ - - ctor:function (x, y, id) { - this._lastModified = 0; - this.setTouchInfo(id, x, y); - }, - +cc.Touch = function (x, y, id) { + this._lastModified = 0; + this.setTouchInfo(id, x, y); +}; +cc.Touch.prototype = { + constructor: cc.Touch, /** * !#en Returns the current touch location in OpenGL coordinates.、 * !#zh 获取当前触点位置。 @@ -180,4 +179,4 @@ cc.Touch = cc._Class.extend(/** @lends cc.Touch# */{ else this._prevPoint = cc.p(x || 0, y || 0); } -}); \ No newline at end of file +}; \ No newline at end of file diff --git a/cocos2d/core/event/system-event.js b/cocos2d/core/event/system-event.js index e2301fae37..daed39c740 100644 --- a/cocos2d/core/event/system-event.js +++ b/cocos2d/core/event/system-event.js @@ -132,7 +132,7 @@ var SystemEvent = cc.Class({ } }); } - if (!eventManager.hasEventListener(cc._EventListenerKeyboard.LISTENER_ID)) { + if (!eventManager.hasEventListener(cc.EventListener.ListenerID.KEYBOARD)) { var currentFrame = cc.director.getTotalFrames(); if (currentFrame !== keyboardListenerAddFrame) { eventManager.addListener(keyboardListener, 1); @@ -155,7 +155,7 @@ var SystemEvent = cc.Class({ } }); } - if (!eventManager.hasEventListener(cc._EventListenerAcceleration.LISTENER_ID)) { + if (!eventManager.hasEventListener(cc.EventListener.ListenerID.ACCELERATION)) { eventManager.addListener(accelerationListener, 1); } } diff --git a/cocos2d/core/load-pipeline/asset-loader.js b/cocos2d/core/load-pipeline/asset-loader.js index b4a6ab0cf5..321e3744ef 100644 --- a/cocos2d/core/load-pipeline/asset-loader.js +++ b/cocos2d/core/load-pipeline/asset-loader.js @@ -23,7 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -var Path = require('../utils/CCPath'); +require('../utils/CCPath'); var Pipeline = require('./pipeline'); var LoadingItems = require('./loading-items'); @@ -52,7 +52,7 @@ AssetLoader.prototype.handle = function (item, callback) { item.url = item.rawUrl = url; item.isRawAsset = isRawAsset; if (isRawAsset) { - var ext = Path.extname(url).toLowerCase(); + var ext = cc.path.extname(url).toLowerCase(); if (!ext) { callback(new Error(cc._getError(4931, uuid, url))); return; diff --git a/cocos2d/core/load-pipeline/audio-downloader.js b/cocos2d/core/load-pipeline/audio-downloader.js index b6d536433f..5a0a3c65da 100644 --- a/cocos2d/core/load-pipeline/audio-downloader.js +++ b/cocos2d/core/load-pipeline/audio-downloader.js @@ -23,7 +23,6 @@ THE SOFTWARE. ****************************************************************************/ -var Path = require('../utils/CCPath'); var sys = require('../platform/CCSys'); var Pipeline = require('./pipeline'); var audioEngine = require('../../audio/CCAudioEngine'); diff --git a/cocos2d/core/load-pipeline/downloader.js b/cocos2d/core/load-pipeline/downloader.js index 9df905138d..85fa4bfde8 100644 --- a/cocos2d/core/load-pipeline/downloader.js +++ b/cocos2d/core/load-pipeline/downloader.js @@ -24,7 +24,7 @@ ****************************************************************************/ var JS = require('../platform/js'); var sys = require('../platform/CCSys'); -var Path = require('../utils/CCPath'); +require('../utils/CCPath'); var Pipeline = require('./pipeline'); var PackDownloader = require('./pack-downloader'); // var downloadBinary = require('./binary-downloader'); @@ -143,7 +143,7 @@ function _loadFont (name, srcs, type){ if (srcs instanceof Array) { for (var i = 0, li = srcs.length; i < li; i++) { var src = srcs[i]; - type = Path.extname(src).toLowerCase(); + type = cc.path.extname(src).toLowerCase(); fontStr += 'url(\'' + srcs[i] + '\') format(\'' + FONT_TYPE[type] + '\')'; fontStr += (i === li - 1) ? ';' : ','; } @@ -174,8 +174,8 @@ function downloadFont (item, callback) { } _loadFont(name, srcs); } else { - type = Path.extname(url); - name = Path.basename(url, type); + type = cc.path.extname(url); + name = cc.path.basename(url, type); _loadFont(name, url, type); } if (document.fonts) { diff --git a/cocos2d/core/load-pipeline/loading-items.js b/cocos2d/core/load-pipeline/loading-items.js index 1aaf32e566..dbe3b61b36 100644 --- a/cocos2d/core/load-pipeline/loading-items.js +++ b/cocos2d/core/load-pipeline/loading-items.js @@ -24,7 +24,7 @@ ****************************************************************************/ var CallbacksInvoker = require('../platform/callbacks-invoker'); -var Path = require('../utils/CCPath'); +require('../utils/CCPath'); var JS = require('../platform/js'); var _qid = (0|(Math.random()*998)); @@ -86,7 +86,7 @@ function createItem (id, queueId) { } result.rawUrl = result.url; if (url && !result.type) { - result.type = Path.extname(url).toLowerCase().substr(1); + result.type = cc.path.extname(url).toLowerCase().substr(1); } return result; } diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index f52f520e20..ea3aa36e5d 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -1268,6 +1268,18 @@ function parseAttributes (cls, attrs, className, propName, usedInGetter) { cc.Class = CCClass; +// Merged from old _CCClass + +/** + * ClassManager + */ +cc.ClassManager = { + instanceId: (0 | (Math.random() * 998)), + getNewInstanceId: function () { + return this.instanceId++; + } +}; + module.exports = { isArray: function (defaultVal) { defaultVal = getDefault(defaultVal); diff --git a/cocos2d/core/platform/CCInputExtension.js b/cocos2d/core/platform/CCInputExtension.js index 9f4a1c76fc..6c86a0507b 100644 --- a/cocos2d/core/platform/CCInputExtension.js +++ b/cocos2d/core/platform/CCInputExtension.js @@ -24,7 +24,7 @@ ****************************************************************************/ if (!cc.ClassManager) { - require("./_CCClass"); + require("./CCClass"); } var eventManager = require('../event-manager'); diff --git a/cocos2d/core/platform/CCMacro.js b/cocos2d/core/platform/CCMacro.js index ac844d8955..fb60b1f219 100644 --- a/cocos2d/core/platform/CCMacro.js +++ b/cocos2d/core/platform/CCMacro.js @@ -24,7 +24,7 @@ THE SOFTWARE. ****************************************************************************/ -require('./_CCClass'); +const js = require('./js'); /** * !#en Key map for keyboard event @@ -1143,19 +1143,6 @@ cc.getImageFormatByData = function (imgData) { * @type {Object} */ cc.macro = { - /** - * @property INVALID_INDEX - * @type {Number} - */ - INVALID_INDEX: -1, - - /** - * Default Node tag - * @property NODE_TAG_INVALID - * @type {Number} - */ - NODE_TAG_INVALID: -1, - /** * PI is the ratio of a circle's circumference to its diameter. * @property PI @@ -1296,21 +1283,6 @@ cc.macro = { */ ONE_MINUS_CONSTANT_COLOR: 0x8002, - /** - * the constant variable equals gl.LINEAR for texture - * @property LINEAR - * @type {Number} - */ - LINEAR: 0x2601, - - /** - * default gl blend dst function. Compatible with premultiplied alpha images. - * @property BLEND_DST - * @type {Number} - */ - BLEND_DST: 0x0303, - - //Possible device orientations /** @@ -1362,52 +1334,11 @@ cc.macro = { */ ORIENTATION_AUTO: 3, - DENSITYDPI_DEVICE: 'device-dpi', DENSITYDPI_HIGH: 'high-dpi', DENSITYDPI_MEDIUM: 'medium-dpi', DENSITYDPI_LOW: 'low-dpi', - /** - * default size for font size - * @property ITEM_SIZE - * @type {Number} - */ - ITEM_SIZE: 32, - - /** - * default tag for current item - * @property CURRENT_ITEM - * @type {Number} - */ - CURRENT_ITEM: 0xc0c05001, - /** - * default tag for zoom action tag - * @property ZOOM_ACTION_TAG - * @type {Number} - */ - ZOOM_ACTION_TAG: 0xc0c05002, - /** - * default tag for normal - * @property NORMAL_TAG - * @type {Number} - */ - NORMAL_TAG: 8801, - - /** - * default selected tag - * @property SELECTED_TAG - * @type {Number} - */ - SELECTED_TAG: 8802, - - /** - * default disabled tag - * @property DISABLE_TAG - * @type {Number} - */ - DISABLE_TAG: 8803, - // General configurations /** *
@@ -1460,62 +1391,6 @@ cc.macro = { */ DIRECTOR_STATS_POSITION: cc.p(0, 0), - /** - *
- * Seconds between FPS updates.
- * 0.5 seconds, means that the FPS number will be updated every 0.5 seconds.
- * Having a bigger number means a more reliable FPS
- *
- * Default value: 0.1f
- * To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h
- *
- * If enabled, the ccsg.Node objects (_ccsg.Sprite, _ccsg.Label,etc) will be able to render in subpixels.
- * If disabled, integer pixels will be used.
- *
- * To enable set it to 1. Enabled by default.
- * To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h
- *
- * If enabled, the _ccsg.Sprite objects rendered with cc.SpriteBatchNode will be able to render in subpixels.
- * If disabled, integer pixels will be used.
- *
- * To enable set it to 1. Enabled by default.
- * To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h
- *
- * If most of your images have pre-multiplied alpha, set it to 1 (if you are going to use .PNG/.JPG file images).
- * Only set to 0 if ALL your images by-pass Apple UIImage loading system (eg: if you use libpng or PVR images)
- *
- * To enable set it to a value different than 0. Enabled by default.
- * To modify it, in Web engine please refer to CCMacro.js, in JSB please refer to CCConfig.h
- *
* If enabled, actions that alter the position property (eg: CCMoveBy, CCJumpBy, CCBezierBy, etc..) will be stacked.
@@ -1635,7 +1510,7 @@ cc.macro = {
* @default true
*/
var ENABLE_CULLING = true;
-cc.defineGetterSetter(cc.macro, 'ENABLE_CULLING',
+js.getset(cc.macro, 'ENABLE_CULLING',
function () {
return ENABLE_CULLING;
},
@@ -1656,24 +1531,6 @@ cc.defineGetterSetter(cc.macro, 'ENABLE_CULLING',
}
)
-/**
- * !#en
- * default gl blend src function. Compatible with premultiplied alpha images.
- * !#zh
- * 默认的混合源模式
- * @property BLEND_SRC
- * @type {Number}
- */
-cc.defineGetterSetter(cc.macro, "BLEND_SRC", function (){
- if (cc._renderType === cc.game.RENDER_TYPE_WEBGL
- && cc.macro.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA) {
- return cc.macro.ONE;
- }
- else {
- return cc.macro.SRC_ALPHA;
- }
-});
-
/**
* @module cc
*/
@@ -1737,69 +1594,4 @@ cc.radiansToDegrees = function (angle) {
return angle * cc.macro.DEG;
};
-/**
- * Helpful macro that setups the GL server state, the correct GL program and sets the Model View Projection matrix
- * @param {Node} node setup node
- * @method nodeDrawSetup
- */
-cc.nodeDrawSetup = function (node) {
- //cc.gl.enable(node._glServerState);
- if (node._shaderProgram) {
- //cc._renderContext.useProgram(node._shaderProgram._programObj);
- node._shaderProgram.use();
- node._shaderProgram.setUniformForModelViewAndProjectionMatrixWithMat4();
- }
-};
-
-/*
- *
- * GL states that are enabled:
- * - GL_TEXTURE_2D
- * - GL_VERTEX_ARRAY
- * - GL_TEXTURE_COORD_ARRAY
- * - GL_COLOR_ARRAY
- *
- * Disable default GL states:
- * - GL_TEXTURE_2D
- * - GL_TEXTURE_COORD_ARRAY
- * - GL_COLOR_ARRAY
- *