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 - *

- * @property {Number} DIRECTOR_FPS_INTERVAL - */ - DIRECTOR_FPS_INTERVAL: 0.5, - - /** - *

- * 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 - *

- * @property {Number} COCOSNODE_RENDER_SUBPIXEL - */ - COCOSNODE_RENDER_SUBPIXEL: true, - - /** - *

- * 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 - *

- * @property {Number} SPRITEBATCHNODE_RENDER_SUBPIXEL - */ - SPRITEBATCHNODE_RENDER_SUBPIXEL: true, - - /** - * Automatically premultiply alpha for remote PNG resources. - * @property {Boolean} AUTO_PREMULTIPLIED_ALPHA_FOR_PNG - * @default false - */ - AUTO_PREMULTIPLIED_ALPHA_FOR_PNG: false, - - /** - *

- * 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 - *

- * @property {Number} OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA - */ - OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA: false, - /** *

* 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
- *

- * @method enableDefaultGLStates - */ -// cc.enableDefaultGLStates = function () { - //TODO OPENGL STUFF - /* - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnable(GL_TEXTURE_2D);*/ -// }; - -/* - *

- * Disable default GL states:
- * - GL_TEXTURE_2D
- * - GL_TEXTURE_COORD_ARRAY
- * - GL_COLOR_ARRAY
- *

- * @method disableDefaultGLStates - */ -// cc.disableDefaultGLStates = function () { - //TODO OPENGL - /* - glDisable(GL_TEXTURE_2D); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); - */ -// }; - -/** - * Check webgl error.Error will be shown in console if exists. - * @method checkGLErrorDebug - */ -cc.checkGLErrorDebug = function () { - if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) { - var _error = cc._renderContext.getError(); - if (_error) { - cc.logID(2400, _error); - } - } -}; - module.exports = cc.macro; diff --git a/cocos2d/core/platform/CCSAXParser.js b/cocos2d/core/platform/CCSAXParser.js index 3e763715cc..665fa7dae9 100644 --- a/cocos2d/core/platform/CCSAXParser.js +++ b/cocos2d/core/platform/CCSAXParser.js @@ -24,24 +24,23 @@ THE SOFTWARE. ****************************************************************************/ +var js = require('../platform/js'); + /** * A SAX Parser * @class saxParser */ -cc.SAXParser = cc._Class.extend(/** @lends cc.saxParser# */{ - /** - * Constructor of cc.SAXParser - */ - ctor: function () { - if (window.DOMParser) { - this._isSupportDOMParser = true; - this._parser = new DOMParser(); - } else { - this._isSupportDOMParser = false; - this._parser = null; - } - }, - +cc.SAXParser = function () { + if (window.DOMParser) { + this._isSupportDOMParser = true; + this._parser = new DOMParser(); + } else { + this._isSupportDOMParser = false; + this._parser = null; + } +}; +cc.SAXParser.prototype = { + constructor: cc.SAXParser, /** * @method parse * @param {String} xmlTxt @@ -64,8 +63,7 @@ cc.SAXParser = cc._Class.extend(/** @lends cc.saxParser# */{ } return xmlDoc; } - -}); +}; /** * @@ -73,8 +71,9 @@ cc.SAXParser = cc._Class.extend(/** @lends cc.saxParser# */{ * @class plistParser * @extends SAXParser */ -cc.PlistParser = cc.SAXParser.extend(/** @lends cc.plistParser# */{ - +cc.PlistParser = function () {}; +js.extend(cc.PlistParser, cc.SAXParser); +js.addon(cc.PlistParser.prototype, { /** * parse a xml string as plist object. * @param {String} xmlTxt - plist xml contents diff --git a/cocos2d/core/platform/CCView.js b/cocos2d/core/platform/CCView.js index 59f7518c11..daf3d490ff 100644 --- a/cocos2d/core/platform/CCView.js +++ b/cocos2d/core/platform/CCView.js @@ -23,9 +23,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -var eventManager = require('../event-manager'); +const eventManager = require('../event-manager'); +const js = require('../platform/js'); const renderer = require('../renderer'); +require('../platform/CCClass'); function isWeChatGame () { return window['wx']; @@ -112,70 +114,68 @@ var _scissorRect = null; * * @class View */ -var View = cc._Class.extend({ - /** - * Constructor of View - */ - ctor: function () { - var _t = this, _strategyer = cc.ContainerStrategy, _strategy = cc.ContentStrategy; +var View = function () { + var _t = this, _strategyer = cc.ContainerStrategy, _strategy = cc.ContentStrategy; - __BrowserGetter.init(this); + __BrowserGetter.init(this); - // Size of parent node that contains cc.container and cc.game.canvas - _t._frameSize = cc.size(0, 0); - _t._initFrameSize(); + // Size of parent node that contains cc.container and cc.game.canvas + _t._frameSize = cc.size(0, 0); + _t._initFrameSize(); - var w = cc.game.canvas.width, h = cc.game.canvas.height; - // resolution size, it is the size appropriate for the app resources. - _t._designResolutionSize = cc.size(w, h); - _t._originalDesignResolutionSize = cc.size(w, h); - // Viewport is the container's rect related to content's coordinates in pixel - _t._viewPortRect = cc.rect(0, 0, w, h); - // The visible rect in content's coordinate in point - _t._visibleRect = cc.rect(0, 0, w, h); - _t._contentTranslateLeftTop = {left: 0, top: 0}; - _t._autoFullScreen = false; - // The device's pixel ratio (for retina displays) - _t._devicePixelRatio = 1; - // the view name - _t._viewName = "Cocos2dHTML5"; - // Custom callback for resize event - _t._resizeCallback = null; - _t._orientationChanging = true; - _t._resizing = false; + var w = cc.game.canvas.width, h = cc.game.canvas.height; + // resolution size, it is the size appropriate for the app resources. + _t._designResolutionSize = cc.size(w, h); + _t._originalDesignResolutionSize = cc.size(w, h); + // Viewport is the container's rect related to content's coordinates in pixel + _t._viewPortRect = cc.rect(0, 0, w, h); + // The visible rect in content's coordinate in point + _t._visibleRect = cc.rect(0, 0, w, h); + _t._contentTranslateLeftTop = {left: 0, top: 0}; + _t._autoFullScreen = false; + // The device's pixel ratio (for retina displays) + _t._devicePixelRatio = 1; + // the view name + _t._viewName = "Cocos2dHTML5"; + // Custom callback for resize event + _t._resizeCallback = null; + _t._orientationChanging = true; + _t._resizing = false; - _t._scaleX = 1; - _t._originalScaleX = 1; - _t._scaleY = 1; - _t._originalScaleY = 1; + _t._scaleX = 1; + _t._originalScaleX = 1; + _t._scaleY = 1; + _t._originalScaleY = 1; - _t._isRotated = false; - _t._orientation = 3; + _t._isRotated = false; + _t._orientation = 3; - var sys = cc.sys; - _t.enableRetina(sys.os === sys.OS_IOS || sys.os === sys.OS_OSX); - cc.visibleRect && cc.visibleRect.init(_t._visibleRect); + var sys = cc.sys; + _t.enableRetina(sys.os === sys.OS_IOS || sys.os === sys.OS_OSX); + cc.visibleRect && cc.visibleRect.init(_t._visibleRect); - // Setup system default resolution policies - _t._resolutionPolicy = null; - _t._rpExactFit = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.EXACT_FIT); - _t._rpShowAll = new cc.ResolutionPolicy(_strategyer.PROPORTION_TO_FRAME, _strategy.SHOW_ALL); - _t._rpNoBorder = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.NO_BORDER); - _t._rpFixedHeight = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_HEIGHT); - _t._rpFixedWidth = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_WIDTH); + // Setup system default resolution policies + _t._resolutionPolicy = null; + _t._rpExactFit = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.EXACT_FIT); + _t._rpShowAll = new cc.ResolutionPolicy(_strategyer.PROPORTION_TO_FRAME, _strategy.SHOW_ALL); + _t._rpNoBorder = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.NO_BORDER); + _t._rpFixedHeight = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_HEIGHT); + _t._rpFixedWidth = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_WIDTH); - _t._initialized = false; + _t._initialized = false; - _t._contentTranslateLeftTop = null; + _t._contentTranslateLeftTop = null; - _t._frameZoomFactor = 1.0; - _t.__resizeWithBrowserSize = false; - _t._isAdjustViewPort = true; + _t._frameZoomFactor = 1.0; + _t.__resizeWithBrowserSize = false; + _t._isAdjustViewPort = true; - _t._targetDensityDPI = cc.macro.DENSITYDPI_HIGH; - _t.enableAntiAlias(true); - }, + _t._targetDensityDPI = cc.macro.DENSITYDPI_HIGH; + _t.enableAntiAlias(true); +}; +View.prototype = { + constructor: View, // Resize helper functions _resizeEvent: function () { var view; @@ -986,7 +986,7 @@ var View = cc._Class.extend({ selPrePoint.y = (selPrePoint.y - viewport.y) / scaleY; } } -}); +}; /** * @method _getInstance @@ -1007,7 +1007,8 @@ View._getInstance = function () { * * @class ContainerStrategy */ -cc.ContainerStrategy = cc._Class.extend(/** @lends cc.ContainerStrategy# */{ +cc.ContainerStrategy = cc.Class({ + name: "ContainerStrategy", /** * Manipulation before appling the strategy * @method preApply @@ -1079,11 +1080,14 @@ cc.ContainerStrategy = cc._Class.extend(/** @lends cc.ContainerStrategy# */{ * * @class ContentStrategy */ -cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{ +cc.ContentStrategy = cc.Class({ + name: "ContentStrategy", - _result: { - scale: [1, 1], - viewport: null + ctor: function () { + this._result = { + scale: [1, 1], + viewport: null + }; }, _buildResult: function (containerW, containerH, contentW, contentH, scaleX, scaleY) { @@ -1143,7 +1147,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{ * @class EqualToFrame * @extends ContainerStrategy */ - var EqualToFrame = cc.ContainerStrategy.extend({ + var EqualToFrame = cc.Class({ + name: "EqualToFrame", + extends: cc.ContainerStrategy, apply: function (view) { var frameH = view._frameSize.height, containerStyle = cc.container.style; this._setupContainer(view, view._frameSize.width, view._frameSize.height); @@ -1162,7 +1168,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{ * @class ProportionalToFrame * @extends ContainerStrategy */ - var ProportionalToFrame = cc.ContainerStrategy.extend({ + var ProportionalToFrame = cc.Class({ + name: "ProportionalToFrame", + extends: cc.ContainerStrategy, apply: function (view, designedResolution) { var frameW = view._frameSize.width, frameH = view._frameSize.height, containerStyle = cc.container.style, designW = designedResolution.width, designH = designedResolution.height, @@ -1198,7 +1206,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{ * @class EqualToWindow * @extends EqualToFrame */ - var EqualToWindow = EqualToFrame.extend({ + var EqualToWindow = cc.Class({ + name: "EqualToWindow", + extends: EqualToFrame, preApply: function (view) { this._super(view); cc.game.frame = document.documentElement; @@ -1214,7 +1224,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{ * @class ProportionalToWindow * @extends ProportionalToFrame */ - var ProportionalToWindow = ProportionalToFrame.extend({ + var ProportionalToWindow = cc.Class({ + name: "ProportionalToWindow", + extends: ProportionalToFrame, preApply: function (view) { this._super(view); cc.game.frame = document.documentElement; @@ -1230,7 +1242,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{ * @class OriginalContainer * @extends ContainerStrategy */ - var OriginalContainer = cc.ContainerStrategy.extend({ + var OriginalContainer = cc.Class({ + name: "OriginalContainer", + extends: cc.ContainerStrategy, apply: function (view) { this._setupContainer(view, cc.game.canvas.width, cc.game.canvas.height); } @@ -1248,7 +1262,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{ cc.ContainerStrategy.ORIGINAL_CONTAINER = new OriginalContainer(); // Content scale strategys - var ExactFit = cc.ContentStrategy.extend({ + var ExactFit = cc.Class({ + name: "ExactFit", + extends: cc.ContentStrategy, apply: function (view, designedResolution) { var containerW = cc.game.canvas.width, containerH = cc.game.canvas.height, scaleX = containerW / designedResolution.width, scaleY = containerH / designedResolution.height; @@ -1257,7 +1273,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{ } }); - var ShowAll = cc.ContentStrategy.extend({ + var ShowAll = cc.Class({ + name: "ShowAll", + extends: cc.ContentStrategy, apply: function (view, designedResolution) { var containerW = cc.game.canvas.width, containerH = cc.game.canvas.height, designW = designedResolution.width, designH = designedResolution.height, @@ -1271,7 +1289,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{ } }); - var NoBorder = cc.ContentStrategy.extend({ + var NoBorder = cc.Class({ + name: "NoBorder", + extends: cc.ContentStrategy, apply: function (view, designedResolution) { var containerW = cc.game.canvas.width, containerH = cc.game.canvas.height, designW = designedResolution.width, designH = designedResolution.height, @@ -1285,7 +1305,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{ } }); - var FixedHeight = cc.ContentStrategy.extend({ + var FixedHeight = cc.Class({ + name: "FixedHeight", + extends: cc.ContentStrategy, apply: function (view, designedResolution) { var containerW = cc.game.canvas.width, containerH = cc.game.canvas.height, designH = designedResolution.height, scale = containerH / designH, @@ -1299,7 +1321,9 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{ } }); - var FixedWidth = cc.ContentStrategy.extend({ + var FixedWidth = cc.Class({ + name: "FixedWidth", + extends: cc.ContentStrategy, apply: function (view, designedResolution) { var containerW = cc.game.canvas.width, containerH = cc.game.canvas.height, designW = designedResolution.width, scale = containerW / designW, @@ -1337,16 +1361,16 @@ cc.ContentStrategy = cc._Class.extend(/** @lends cc.ContentStrategy# */{ * @param {ContainerStrategy} containerStg The container strategy * @param {ContentStrategy} contentStg The content strategy */ -cc.ResolutionPolicy = cc._Class.extend(/** @lends cc.ResolutionPolicy# */{ - _containerStrategy: null, - _contentStrategy: null, - +cc.ResolutionPolicy = cc.Class({ + name: "cc.ResolutionPolicy", /** * Constructor of cc.ResolutionPolicy * @param {ContainerStrategy} containerStg * @param {ContentStrategy} contentStg */ ctor: function (containerStg, contentStg) { + this._containerStrategy = null; + this._contentStrategy = null; this.setContainerStrategy(containerStg); this.setContentStrategy(contentStg); }, @@ -1406,7 +1430,7 @@ cc.ResolutionPolicy = cc._Class.extend(/** @lends cc.ResolutionPolicy# */{ } }); -cc.js.get(cc.ResolutionPolicy.prototype, "canvasSize", function () { +js.get(cc.ResolutionPolicy.prototype, "canvasSize", function () { return cc.v2(cc.game.canvas.width, cc.game.canvas.height); }); diff --git a/cocos2d/core/platform/_CCClass.js b/cocos2d/core/platform/_CCClass.js deleted file mode 100644 index 644320e987..0000000000 --- a/cocos2d/core/platform/_CCClass.js +++ /dev/null @@ -1,227 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Chukong Aipu reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -/** - * ClassManager - */ -var ClassManager = cc.ClassManager = { - instanceId: (0 | (Math.random() * 998)), - getNewInstanceId: function () { - return this.instanceId++; - } -}; - -/* Managed JavaScript Inheritance - * Based on John Resig's Simple JavaScript Inheritance http://ejohn.org/blog/simple-javascript-inheritance/ - * MIT Licensed. - */ -var fnTest = /\b_super\b/; - -/** - * The base Class implementation (does nothing) - * @class Class - * @private - */ -var Class = function () { -}; - -/** - * Create a new Class that inherits from this Class - * @static - * @param {Object} props - * @return {Function} - */ -Class.extend = function (props) { - var _super = this.prototype; - - // Instantiate a base Class (but only create the instance, - // don't run the init constructor) - var proto = Object.create(_super); - - // Copy the properties over onto the new prototype. We make function - // properties non-eumerable as this makes typeof === 'function' check - // unnecessary in the for...in loop used 1) for generating Class() - // 2) for cc.clone and perhaps more. It is also required to make - // these function properties cacheable in Carakan. - var desc = { writable: true, enumerable: false, configurable: true }; - - // The dummy Class constructor - var TheClass; - if (CC_SUPPORT_JIT && cc.game && cc.game.config && cc.game.config[cc.game.CONFIG_KEY.exposeClassName]) { - var ctor = - "return (function " + (props._className || "Class") + "(arg0,arg1,arg2,arg3,arg4) {\n" + - "this.__instanceId = cc.ClassManager.getNewInstanceId();\n" + - "if (this.ctor) {\n" + - "switch (arguments.length) {\n" + - "case 0: this.ctor(); break;\n" + - "case 1: this.ctor(arg0); break;\n" + - "case 2: this.ctor(arg0,arg1); break;\n" + - "case 3: this.ctor(arg0,arg1,arg2); break;\n" + - "case 4: this.ctor(arg0,arg1,arg2,arg3); break;\n" + - "case 5: this.ctor(arg0,arg1,arg2,arg3,arg4); break;\n" + - "default: this.ctor.apply(this, arguments);\n" + - "}\n" + - "}\n" + - "});"; - TheClass = Function(ctor)(); - } - else { - TheClass = function (arg0, arg1, arg2, arg3, arg4) { - this.__instanceId = ClassManager.getNewInstanceId(); - if (this.ctor) { - switch (arguments.length) { - case 0: this.ctor(); break; - case 1: this.ctor(arg0); break; - case 2: this.ctor(arg0, arg1); break; - case 3: this.ctor(arg0, arg1, arg2); break; - case 4: this.ctor(arg0, arg1, arg2, arg3); break; - case 5: this.ctor(arg0, arg1, arg2, arg3, arg4); break; - default: this.ctor.apply(this, arguments); - } - } - }; - } - - // Populate our constructed prototype object - TheClass.prototype = proto; - - // Enforce the constructor to be what we expect - desc.value = TheClass; - Object.defineProperty(proto, 'constructor', desc); - - for (var name in props) { - var isFunc = (typeof props[name] === "function"); - var override = isFunc && (typeof _super[name] === "function"); - var hasSuperCall = override && fnTest.test(props[name]); - - if (hasSuperCall) { - desc.value = (function (name, fn) { - return function () { - var tmp = this._super; - - // Add a new ._super() method that is the same method - // but on the super-Class - this._super = _super[name]; - - // The method only need to be bound temporarily, so we - // remove it when we're done executing - var ret = fn.apply(this, arguments); - this._super = tmp; - - return ret; - }; - })(name, props[name]); - Object.defineProperty(proto, name, desc); - } else if (isFunc) { - desc.value = props[name]; - Object.defineProperty(proto, name, desc); - } else { - proto[name] = props[name]; - } - } - - // And make this Class extendable - TheClass.extend = Class.extend; - - //add implementation method - TheClass.implement = function (prop) { - for (var name in prop) { - proto[name] = prop[name]; - } - }; - return TheClass; -}; - -/** - * Common getter setter configuration function - * @method defineGetterSetter - * @param {Object} proto - A class prototype or an object to config
- * @param {String} prop - Property name - * @param {Function} getter - Getter function for the property - * @param {Function} setter - Setter function for the property - * @param {String} getterName - Name of getter function for the property - * @param {String} setterName - Name of setter function for the property - */ -cc.defineGetterSetter = function (proto, prop, getter, setter, getterName, setterName) { - if (proto.__defineGetter__) { - getter && proto.__defineGetter__(prop, getter); - setter && proto.__defineSetter__(prop, setter); - } else if (Object.defineProperty) { - var desc = { configurable: true }; // enumerable is false by default - getter && (desc.get = getter); - setter && (desc.set = setter); - Object.defineProperty(proto, prop, desc); - } else { - throw new Error(cc._getError(3658)); - } -}; - -/** - * Create a new object and copy all properties in an exist object to the new object - * @method clone - * @param {Object|Array} obj - The source object - * @return {Array|Object} The created object - */ -cc.clone = function (obj) { - // Cloning is better if the new object is having the same prototype chain - // as the copied obj (or otherwise, the cloned object is certainly going to - // have a different hidden class). Play with C1/C2 of the - // PerformanceVirtualMachineTests suite to see how this makes an impact - // under extreme conditions. - // - // Object.create(Object.getPrototypeOf(obj)) doesn't work well because the - // prototype lacks a link to the constructor (Carakan, V8) so the new - // object wouldn't have the hidden class that's associated with the - // constructor (also, for whatever reasons, utilizing - // Object.create(Object.getPrototypeOf(obj)) + Object.defineProperty is even - // slower than the original in V8). Therefore, we call the constructor, but - // there is a big caveat - it is possible that the this.init() in the - // constructor would throw with no argument. It is also possible that a - // derived class forgets to set "constructor" on the prototype. We ignore - // these possibities for and the ultimate solution is a standardized - // Object.clone(). - var newObj = (obj.constructor) ? new obj.constructor : {}; - - // Assuming that the constuctor above initialized all properies on obj, the - // following keyed assignments won't turn newObj into dictionary mode - // becasue they're not *appending new properties* but *assigning existing - // ones* (note that appending indexed properties is another story). See - // CCClass.js for a link to the devils when the assumption fails. - for (var key in obj) { - var copy = obj[key]; - // Beware that typeof null == "object" ! - if (typeof copy === "object" && - copy && - !(copy instanceof _ccsg.Node) && - (CC_JSB || !(copy instanceof HTMLElement))) { - newObj[key] = cc.clone(copy); - } else { - newObj[key] = copy; - } - } - return newObj; -}; - -cc._Class = module.exports = Class; diff --git a/cocos2d/core/renderer/assemblers/label/bmfont-assembler.js b/cocos2d/core/renderer/assemblers/label/bmfont-assembler.js index ca0e638055..e44d2553cc 100644 --- a/cocos2d/core/renderer/assemblers/label/bmfont-assembler.js +++ b/cocos2d/core/renderer/assemblers/label/bmfont-assembler.js @@ -29,6 +29,8 @@ const RenderData = renderEngine.RenderData; const Label = require('../../../components/CCLabel'); const Overflow = Label.Overflow; +const TextUtils = require('../../../utils/text-utils').TextUtils; + const spriteAssembler = require('../sprite/simple'); let FontLetterDefinition = function() { @@ -315,7 +317,7 @@ module.exports = { && _maxLineWidth > 0 && nextTokenX > 0 && letterX + letterDef._width * _bmfontScale > _maxLineWidth - && !cc.TextUtils.isUnicodeSpace(character)) { + && !TextUtils.isUnicodeSpace(character)) { _linesWidth.push(letterRight); letterRight = 0; lineIndex++; @@ -401,9 +403,9 @@ module.exports = { _getFirstWordLen: function(text, startIndex, textLen) { let character = text.charAt(startIndex); - if (cc.TextUtils.isUnicodeCJK(character) + if (TextUtils.isUnicodeCJK(character) || character === "\n" - || cc.TextUtils.isUnicodeSpace(character)) { + || TextUtils.isUnicodeSpace(character)) { return 1; } @@ -424,14 +426,14 @@ module.exports = { letterX = nextLetterX + letterDef._offsetX * _bmfontScale; if(letterX + letterDef._width * _bmfontScale > _maxLineWidth - && !cc.TextUtils.isUnicodeSpace(character) + && !TextUtils.isUnicodeSpace(character) && _maxLineWidth > 0) { return len; } nextLetterX += letterDef._xAdvance * _bmfontScale + _spacingX; if (character === "\n" - || cc.TextUtils.isUnicodeSpace(character) - || cc.TextUtils.isUnicodeCJK(character)) { + || TextUtils.isUnicodeSpace(character) + || TextUtils.isUnicodeCJK(character)) { break; } len++; diff --git a/cocos2d/core/renderer/assemblers/label/ttf-assembler.js b/cocos2d/core/renderer/assemblers/label/ttf-assembler.js index 621c1d8001..87a2e0a880 100644 --- a/cocos2d/core/renderer/assemblers/label/ttf-assembler.js +++ b/cocos2d/core/renderer/assemblers/label/ttf-assembler.js @@ -29,6 +29,9 @@ const RenderData = renderEngine.RenderData; const Label = require('../../../components/CCLabel'); const LabelOutline = require('../../../components/CCLabelOutline'); const Overflow = Label.Overflow; +const utils = require('../../../utils/text-utils'); +const TextUtils = utils.TextUtils; +const CustomFontLoader = utils.CustomFontLoader; const spriteAssembler = require('../sprite/simple'); @@ -179,10 +182,10 @@ module.exports = { if (!_comp.font) return false; let url = _comp.font.nativeUrl; - _fontFamily = cc.CustomFontLoader._getFontFamily(url); - let fontDescriptor = cc.CustomFontLoader._fontCache[_fontFamily]; + _fontFamily = CustomFontLoader._getFontFamily(url); + let fontDescriptor = CustomFontLoader._fontCache[_fontFamily]; if (!fontDescriptor || !fontDescriptor.isLoaded()) { - cc.CustomFontLoader.loadTTF(url); + CustomFontLoader.loadTTF(url); return false; } } @@ -398,10 +401,10 @@ module.exports = { var canvasWidthNoMargin = _canvasSize.width - 2 * _margin; for (i = 0; i < paragraphedStrings.length; ++i) { var allWidth = _context.measureText(paragraphedStrings[i]).width; - var textFragment = cc.TextUtils.fragmentText(paragraphedStrings[i], - allWidth, - canvasWidthNoMargin, - this._measureText(_context)); + var textFragment = TextUtils.fragmentText(paragraphedStrings[i], + allWidth, + canvasWidthNoMargin, + this._measureText(_context)); _splitedStrings = _splitedStrings.concat(textFragment); } } @@ -498,10 +501,10 @@ module.exports = { for (i = 0; i < paragraphedStrings.length; ++i) { var j = 0; var allWidth = _context.measureText(paragraphedStrings[i]).width; - textFragment = cc.TextUtils.fragmentText(paragraphedStrings[i], - allWidth, - canvasWidthNoMargin, - this._measureText(_context)); + textFragment = TextUtils.fragmentText(paragraphedStrings[i], + allWidth, + canvasWidthNoMargin, + this._measureText(_context)); while (j < textFragment.length) { var measureWidth = _context.measureText(textFragment[j]).width; maxLength = measureWidth; diff --git a/cocos2d/core/utils/CCProfiler.js b/cocos2d/core/utils/CCProfiler.js index c7e63247b0..b0a0c9034a 100644 --- a/cocos2d/core/utils/CCProfiler.js +++ b/cocos2d/core/utils/CCProfiler.js @@ -25,7 +25,6 @@ var PStats = require('../../../external/pstats/pstats'); var macro = require('../platform/CCMacro'); -var renderer = require('../renderer'); var _fps = document.createElement('div'); _fps.id = 'fps'; @@ -51,7 +50,7 @@ function afterVisit () { function afterDraw () { stats('render').end(); - stats('draws').value = renderer.drawCalls; + stats('draws').value = cc.renderer.drawCalls; stats('frame').end(); stats('fps').frame(); stats().tick(); diff --git a/cocos2d/core/label/CCHtmlTextParser.js b/cocos2d/core/utils/html-text-parser.js similarity index 98% rename from cocos2d/core/label/CCHtmlTextParser.js rename to cocos2d/core/utils/html-text-parser.js index 758d828077..5b85231d47 100644 --- a/cocos2d/core/label/CCHtmlTextParser.js +++ b/cocos2d/core/utils/html-text-parser.js @@ -27,7 +27,7 @@ var imageAttrReg = /(\s)*src(\s)*=|(\s)*height(\s)*=|(\s)*width(\s)*=|(\s)*click /** * A utils class for parsing HTML texts. The parsed results will be an object array. */ -cc.HtmlTextParser = function() { +var HtmlTextParser = function() { this._parsedObject = {}; this._specialSymbolArray = []; this._specialSymbolArray.push([/</g, '<']); @@ -37,8 +37,8 @@ cc.HtmlTextParser = function() { this._specialSymbolArray.push([/'/g, '\'']); }; -cc.HtmlTextParser.prototype = { - constructor: cc.HtmlTextParser, +HtmlTextParser.prototype = { + constructor: HtmlTextParser, parse: function(htmlString) { this._resultObjectArray = []; this._stack = []; @@ -325,5 +325,8 @@ cc.HtmlTextParser.prototype = { } }; +if (CC_TEST) { + cc._Test.HtmlTextParser = HtmlTextParser; +} -cc.htmlTextParser = new cc.HtmlTextParser(); +module.exports = HtmlTextParser; \ No newline at end of file diff --git a/cocos2d/core/label/CCTextUtils.js b/cocos2d/core/utils/text-utils.js similarity index 98% rename from cocos2d/core/label/CCTextUtils.js rename to cocos2d/core/utils/text-utils.js index 02b2bfe9e2..89c9e69306 100644 --- a/cocos2d/core/label/CCTextUtils.js +++ b/cocos2d/core/utils/text-utils.js @@ -23,6 +23,8 @@ THE SOFTWARE. ****************************************************************************/ +var HtmlTextParser = require('./html-text-parser'); + var CustomFontDescriptor = function() { this._status = 'unloaded'; //when font is loaded, it will notify each observer in the observers array @@ -323,8 +325,10 @@ var TextUtils = { } return wrappedWords; }, - }; -cc.TextUtils = module.exports = TextUtils; -cc.CustomFontLoader = module.exports = CustomFontLoader; +module.exports = { + HtmlTextParser: HtmlTextParser, + TextUtils: TextUtils, + CustomFontLoader: CustomFontLoader +} diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index f3b3c1700b..6b4442da20 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -603,13 +603,18 @@ if (CC_DEV) { // cc markAsRemovedInObject(cc, ['Scale9Sprite'], 'cc'); + js.get(cc, 'pool', function () { + cc.warnID(1407); + return js.Pool; + }); + if (cc.ActionManager) { js.obsoletes(cc.ActionManager.prototype, 'cc.ActionManager', { 'numberOfRunningActionsInTarget' : 'getNumberOfRunningActionsInTarget' }); } - cc.js.get(cc.Texture2D.prototype, 'getName', function () { + js.get(cc.Texture2D.prototype, 'getName', function () { cc.warnID(1400, 'texture.getName()', 'texture._glID'); return function () { return this._glID || null; diff --git a/cocos2d/index.js b/cocos2d/index.js index 143105a760..611dadb3ba 100644 --- a/cocos2d/index.js +++ b/cocos2d/index.js @@ -1,6 +1,4 @@ require('./core/CCGame'); // ensure modular-cocos2d can determine whether action module is included -require('./actions'); - -require('./core/CCConfiguration'); +require('./actions'); \ No newline at end of file diff --git a/cocos2d/particle/CCPNGReader.js b/cocos2d/particle/CCPNGReader.js index 9cee60f59f..1f7f8b7834 100644 --- a/cocos2d/particle/CCPNGReader.js +++ b/cocos2d/particle/CCPNGReader.js @@ -32,139 +32,140 @@ var Zlib = require('../compression/zlib.min'); * A png file reader * @name PNGReader */ -var PNGReader = cc._Class.extend({ - ctor:function(data){ - var chunkSize, colors, delayDen, delayNum, frame, i, index, key, section, ccshort, text, _i, _j, _ref; - this.data = data; - this.pos = 8; - this.palette = []; - this.imgData = []; - this.transparency = {}; - this.animation = null; - this.text = {}; - frame = null; - while (true) { - chunkSize = this.readUInt32(); - section = ((function() { - var _i, _results; - _results = []; - for (i = _i = 0; _i < 4; i = ++_i) { - _results.push(String.fromCharCode(this.data[this.pos++])); +var PNGReader = function(data){ + var chunkSize, colors, delayDen, delayNum, frame, i, index, key, section, ccshort, text, _i, _j, _ref; + this.data = data; + this.pos = 8; + this.palette = []; + this.imgData = []; + this.transparency = {}; + this.animation = null; + this.text = {}; + frame = null; + while (true) { + chunkSize = this.readUInt32(); + section = ((function() { + var _i, _results; + _results = []; + for (i = _i = 0; _i < 4; i = ++_i) { + _results.push(String.fromCharCode(this.data[this.pos++])); + } + return _results; + }).call(this)).join(''); + switch (section) { + case 'IHDR': + this.width = this.readUInt32(); + this.height = this.readUInt32(); + this.bits = this.data[this.pos++]; + this.colorType = this.data[this.pos++]; + this.compressionMethod = this.data[this.pos++]; + this.filterMethod = this.data[this.pos++]; + this.interlaceMethod = this.data[this.pos++]; + break; + case 'acTL': + this.animation = { + numFrames: this.readUInt32(), + numPlays: this.readUInt32() || Infinity, + frames: [] + }; + break; + case 'PLTE': + this.palette = this.read(chunkSize); + break; + case 'fcTL': + if (frame) { + this.animation.frames.push(frame); } - return _results; - }).call(this)).join(''); - switch (section) { - case 'IHDR': - this.width = this.readUInt32(); - this.height = this.readUInt32(); - this.bits = this.data[this.pos++]; - this.colorType = this.data[this.pos++]; - this.compressionMethod = this.data[this.pos++]; - this.filterMethod = this.data[this.pos++]; - this.interlaceMethod = this.data[this.pos++]; - break; - case 'acTL': - this.animation = { - numFrames: this.readUInt32(), - numPlays: this.readUInt32() || Infinity, - frames: [] - }; - break; - case 'PLTE': - this.palette = this.read(chunkSize); - break; - case 'fcTL': - if (frame) { - this.animation.frames.push(frame); - } + this.pos += 4; + frame = { + width: this.readUInt32(), + height: this.readUInt32(), + xOffset: this.readUInt32(), + yOffset: this.readUInt32() + }; + delayNum = this.readUInt16(); + delayDen = this.readUInt16() || 100; + frame.delay = 1000 * delayNum / delayDen; + frame.disposeOp = this.data[this.pos++]; + frame.blendOp = this.data[this.pos++]; + frame.data = []; + break; + case 'IDAT': + case 'fdAT': + if (section === 'fdAT') { this.pos += 4; - frame = { - width: this.readUInt32(), - height: this.readUInt32(), - xOffset: this.readUInt32(), - yOffset: this.readUInt32() - }; - delayNum = this.readUInt16(); - delayDen = this.readUInt16() || 100; - frame.delay = 1000 * delayNum / delayDen; - frame.disposeOp = this.data[this.pos++]; - frame.blendOp = this.data[this.pos++]; - frame.data = []; - break; - case 'IDAT': - case 'fdAT': - if (section === 'fdAT') { - this.pos += 4; - chunkSize -= 4; - } - data = (frame != null ? frame.data : void 0) || this.imgData; - for (i = _i = 0; 0 <= chunkSize ? _i < chunkSize : _i > chunkSize; i = 0 <= chunkSize ? ++_i : --_i) { - data.push(this.data[this.pos++]); - } - break; - case 'tRNS': - this.transparency = {}; - switch (this.colorType) { - case 3: - this.transparency.indexed = this.read(chunkSize); - ccshort = 255 - this.transparency.indexed.length; - if (ccshort > 0) { - for (i = _j = 0; 0 <= ccshort ? _j < ccshort : _j > ccshort; i = 0 <= ccshort ? ++_j : --_j) { - this.transparency.indexed.push(255); - } + chunkSize -= 4; + } + data = (frame != null ? frame.data : void 0) || this.imgData; + for (i = _i = 0; 0 <= chunkSize ? _i < chunkSize : _i > chunkSize; i = 0 <= chunkSize ? ++_i : --_i) { + data.push(this.data[this.pos++]); + } + break; + case 'tRNS': + this.transparency = {}; + switch (this.colorType) { + case 3: + this.transparency.indexed = this.read(chunkSize); + ccshort = 255 - this.transparency.indexed.length; + if (ccshort > 0) { + for (i = _j = 0; 0 <= ccshort ? _j < ccshort : _j > ccshort; i = 0 <= ccshort ? ++_j : --_j) { + this.transparency.indexed.push(255); } - break; + } + break; + case 0: + this.transparency.grayscale = this.read(chunkSize)[0]; + break; + case 2: + this.transparency.rgb = this.read(chunkSize); + } + break; + case 'tEXt': + text = this.read(chunkSize); + index = text.indexOf(0); + key = String.fromCharCode.apply(String, text.slice(0, index)); + this.text[key] = String.fromCharCode.apply(String, text.slice(index + 1)); + break; + case 'IEND': + if (frame) { + this.animation.frames.push(frame); + } + this.colors = (function() { + switch (this.colorType) { case 0: - this.transparency.grayscale = this.read(chunkSize)[0]; - break; + case 3: + case 4: + return 1; case 2: - this.transparency.rgb = this.read(chunkSize); + case 6: + return 3; } - break; - case 'tEXt': - text = this.read(chunkSize); - index = text.indexOf(0); - key = String.fromCharCode.apply(String, text.slice(0, index)); - this.text[key] = String.fromCharCode.apply(String, text.slice(index + 1)); - break; - case 'IEND': - if (frame) { - this.animation.frames.push(frame); + }).call(this); + this.hasAlphaChannel = (_ref = this.colorType) === 4 || _ref === 6; + colors = this.colors + (this.hasAlphaChannel ? 1 : 0); + this.pixelBitlength = this.bits * colors; + this.colorSpace = (function() { + switch (this.colors) { + case 1: + return 'DeviceGray'; + case 3: + return 'DeviceRGB'; } - this.colors = (function() { - switch (this.colorType) { - case 0: - case 3: - case 4: - return 1; - case 2: - case 6: - return 3; - } - }).call(this); - this.hasAlphaChannel = (_ref = this.colorType) === 4 || _ref === 6; - colors = this.colors + (this.hasAlphaChannel ? 1 : 0); - this.pixelBitlength = this.bits * colors; - this.colorSpace = (function() { - switch (this.colors) { - case 1: - return 'DeviceGray'; - case 3: - return 'DeviceRGB'; - } - }).call(this); - if(Uint8Array != Array) - this.imgData = new Uint8Array(this.imgData); - return; - default: - this.pos += chunkSize; - } - this.pos += 4; - if (this.pos > this.data.length) { - throw new Error(cc._getError(6017)); - } + }).call(this); + if(Uint8Array != Array) + this.imgData = new Uint8Array(this.imgData); + return; + default: + this.pos += chunkSize; } - }, + this.pos += 4; + if (this.pos > this.data.length) { + throw new Error(cc._getError(6017)); + } + } +}; +PNGReader.prototype = { + constructor: PNGReader, read:function(bytes){ var i, _i, _results; _results = []; @@ -328,6 +329,6 @@ var PNGReader = cc._Class.extend({ return ctx.putImageData(data, 0, 0); } -}); +}; module.exports = PNGReader; \ No newline at end of file diff --git a/cocos2d/tilemap/CCTMXXMLParser.js b/cocos2d/tilemap/CCTMXXMLParser.js index f685295ba1..3bb8988525 100644 --- a/cocos2d/tilemap/CCTMXXMLParser.js +++ b/cocos2d/tilemap/CCTMXXMLParser.js @@ -26,6 +26,7 @@ var codec = require('../compression/ZipUtils'); var Zlib = require('../compression/zlib.min'); +var js = require('../core/platform/js'); function uint8ArrayToUint32Array (uint8Arr) { if(uint8Arr.length % 4 !== 0) @@ -50,26 +51,25 @@ function uint8ArrayToUint32Array (uint8Arr) { * - Whether the layer is visible (if it's not visible, then the CocosNode won't be created)
*
* This information is obtained from the TMX file.

- * @class - * @extends cc._Class + * @class TMXLayerInfo * * @property {Array} properties - Properties of the layer info. */ -cc.TMXLayerInfo = cc._Class.extend(/** @lends cc.TMXLayerInfo# */{ - - ctor () { - this.properties = {}; - this.name = ""; - this._layerSize = null; - this._tiles = []; - this.visible = true; - this._opacity = 0; - this.ownTiles = true; - this._minGID = 100000; - this._maxGID = 0; - this.offset = cc.p(0,0); - }, +cc.TMXLayerInfo = function () { + this.properties = {}; + this.name = ""; + this._layerSize = null; + this._tiles = []; + this.visible = true; + this._opacity = 0; + this.ownTiles = true; + this._minGID = 100000; + this._maxGID = 0; + this.offset = cc.p(0,0); +}; +cc.TMXLayerInfo.prototype = { + constructor: cc.TMXLayerInfo, /** * Gets the Properties. * @return {Array} @@ -85,7 +85,7 @@ cc.TMXLayerInfo = cc._Class.extend(/** @lends cc.TMXLayerInfo# */{ setProperties (value) { this.properties = value; } -}); +}; /** *

cc.TMXObjectGroupInfo contains the information about the object group like:
@@ -95,24 +95,23 @@ cc.TMXLayerInfo = cc._Class.extend(/** @lends cc.TMXLayerInfo# */{ * - Whether the group is visible
*
* This information is obtained from the TMX file.

- * @class - * @extends cc._Class + * @class TMXObjectGroupInfo * * @property {Array} properties - Properties of the ObjectGroup info. */ -cc.TMXObjectGroupInfo = cc._Class.extend(/** @lends cc.TMXObjectGroupInfo# */{ - - ctor () { - this.properties = {}; - this.name = ""; - this._objects = []; - this.visible = true; - this._opacity = 0; - this._color = new cc.Color(255, 255, 255, 255); - this.offset = cc.p(0,0); - this._draworder = 'topdown'; - }, +cc.TMXObjectGroupInfo = function () { + this.properties = {}; + this.name = ""; + this._objects = []; + this.visible = true; + this._opacity = 0; + this._color = new cc.Color(255, 255, 255, 255); + this.offset = cc.p(0,0); + this._draworder = 'topdown'; +}; +cc.TMXObjectGroupInfo.prototype = { + constructor: cc.TMXObjectGroupInfo, /** * Gets the Properties. * @return {Array} @@ -128,7 +127,7 @@ cc.TMXObjectGroupInfo = cc._Class.extend(/** @lends cc.TMXObjectGroupInfo# */{ setProperties (value) { this.properties = value; } -}); +}; /** *

cc.TMXTilesetInfo contains the information about the tilesets like:
@@ -140,8 +139,7 @@ cc.TMXObjectGroupInfo = cc._Class.extend(/** @lends cc.TMXObjectGroupInfo# */{ * - Image size
* * This information is obtained from the TMX file.

- * @class - * @extends cc._Class + * @class TMXTilesetInfo * * @property {string} name - Tileset name * @property {number} firstGid - First grid @@ -150,27 +148,26 @@ cc.TMXObjectGroupInfo = cc._Class.extend(/** @lends cc.TMXObjectGroupInfo# */{ * @property {null} sourceImage - Texture containing the tiles (should be sprite sheet / texture atlas) * @property {cc.Size} imageSize - Size in pixels of the image */ -cc.TMXTilesetInfo = cc._Class.extend(/** @lends cc.TMXTilesetInfo# */{ +cc.TMXTilesetInfo = function () { + // Tileset name + this.name = ""; + // First grid + this.firstGid = 0; + // Spacing + this.spacing = 0; + // Margin + this.margin = 0; + // Texture containing the tiles (should be sprite sheet / texture atlas) + this.sourceImage = null; + // Size in pixels of the image + this.imageSize = cc.size(0, 0); - ctor () { - // Tileset name - this.name = ""; - // First grid - this.firstGid = 0; - // Spacing - this.spacing = 0; - // Margin - this.margin = 0; - // Texture containing the tiles (should be sprite sheet / texture atlas) - this.sourceImage = null; - // Size in pixels of the image - this.imageSize = cc.size(0, 0); - - this.tileOffset = cc.p(0, 0); - - this._tileSize = cc.size(0, 0); - }, + this.tileOffset = cc.p(0, 0); + this._tileSize = cc.size(0, 0); +}; +cc.TMXTilesetInfo.prototype = { + constructor: cc.TMXTilesetInfo, /** * Return rect * @param {Number} gid @@ -187,7 +184,7 @@ cc.TMXTilesetInfo = cc._Class.extend(/** @lends cc.TMXTilesetInfo# */{ rect.y = parseInt(parseInt(gid / max_x, 10) * (this._tileSize.height + this.spacing) + this.margin, 10); return rect; } -}); +}; function getPropertyList (node) { let res = []; @@ -241,53 +238,46 @@ function getPropertyList (node) { * let xmlStr = cc.loader.getRes(filePath); * let tmxMapInfo = new cc.TMXMapInfo(xmlStr, resources); */ -cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{ - properties:null, - orientation:null, - parentElement:null, - parentGID:null, - layerAttrs:0, - storingCharacters:false, - currentString:null, - _objectGroups:null, - _allChildren: null, - _mapSize:null, - _tileSize:null, - _layers:null, - _tilesets:null, - // tile properties - _tileProperties:null, - _resources: "", // used to load relative tsx +/** + * Creates a TMX Format with a tmx file or content string
+ * Constructor of cc.TMXMapInfo + * @method constructor + * @param {String} tmxFile content string + * @param {String} resourcePath + * @param {Object} textures + */ +cc.TMXMapInfo = function (tmxFile, resourcePath, textures) { + this.properties = []; + this.orientation = null; + this.parentElement = null; + this.parentGID = null; + this.layerAttrs = 0; + this.storingCharacters = false; + this.currentString = null; + + this._parser = new cc.SAXParser(); + this._objectGroups = []; + this._allChildren = []; + this._mapSize = cc.size(0, 0); + this._tileSize = cc.size(0, 0); + this._layers = []; + this._tilesets = []; + this._tileProperties = {}; + this._resources = ""; // map of textures indexed by name - _textures: null, + this._textures = null; // hex map values - _staggerAxis: null, - _staggerIndex: null, - _hexSideLength: 0, + this._staggerAxis = null; + this._staggerIndex = null; + this._hexSideLength = 0; - /** - * Creates a TMX Format with a tmx file or content string
- * Constructor of cc.TMXMapInfo - * @param {String} tmxFile content string - * @param {String} resourcePath - * @param {Object} textures - */ - ctor (tmxFile, resourcePath, textures) { - cc.SAXParser.prototype.ctor.apply(this); - this._mapSize = cc.size(0, 0); - this._tileSize = cc.size(0, 0); - this._layers = []; - this._tilesets = []; - this._objectGroups = []; - this._allChildren = []; - this.properties = []; - this._tileProperties = {}; - - this.initWithXML(tmxFile, resourcePath, textures); - }, + this.initWithXML(tmxFile, resourcePath, textures); +}; +cc.TMXMapInfo.prototype = { + constructor: cc.TMXMapInfo, /** * Gets Map orientation. * @return {Number} @@ -588,7 +578,7 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{ cc.errorID(7220, tmxFile); } - let mapXML = this._parseXML(xmlStr); + let mapXML = this._parser._parseXML(xmlStr); let i, j; // PARSE @@ -993,23 +983,15 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{ setCurrentString (currentString) { this.currentString = currentString; } -}); +}; let _p = cc.TMXMapInfo.prototype; // Extended properties -/** @expose */ -_p.mapWidth; -cc.defineGetterSetter(_p, "mapWidth", _p._getMapWidth, _p._setMapWidth); -/** @expose */ -_p.mapHeight; -cc.defineGetterSetter(_p, "mapHeight", _p._getMapHeight, _p._setMapHeight); -/** @expose */ -_p.tileWidth; -cc.defineGetterSetter(_p, "tileWidth", _p._getTileWidth, _p._setTileWidth); -/** @expose */ -_p.tileHeight; -cc.defineGetterSetter(_p, "tileHeight", _p._getTileHeight, _p._setTileHeight); +js.getset(_p, "mapWidth", _p._getMapWidth, _p._setMapWidth); +js.getset(_p, "mapHeight", _p._getMapHeight, _p._setMapHeight); +js.getset(_p, "tileWidth", _p._getTileWidth, _p._setTileWidth); +js.getset(_p, "tileHeight", _p._getTileHeight, _p._setTileHeight); /** diff --git a/extends.js b/extends.js index e424c7a368..4092d1b65c 100644 --- a/extends.js +++ b/extends.js @@ -36,7 +36,6 @@ else { require('./cocos2d/motion-streak/CCMotionStreak'); require('./cocos2d/core/components/CCStudioComponent'); require('./extensions/ccpool/CCNodePool'); - require('./extensions/ccpool/CCPool'); if (!CC_JSB) { require('./cocos2d/actions'); require('./external/chipmunk/chipmunk'); diff --git a/extensions/ccpool/CCPool.js b/extensions/ccpool/CCPool.js deleted file mode 100644 index 8424fbe1b6..0000000000 --- a/extensions/ccpool/CCPool.js +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** - Copyright (c) 2008-2010 Ricardo Quesada - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var _args = []; - -/** - * !#en - * Attention: In creator, it's strongly not recommended to use cc.pool to manager cc.Node. - * We provided {{#crossLink "NodePool"}}cc.NodePool{{/crossLink}} instead. - * - * cc.pool is a singleton object serves as an object cache pool.
- * It can helps you to improve your game performance for objects which need frequent release and recreate operations
- * !#zh - * 首先请注意,在 Creator 中我们强烈不建议使用 cc.pool 来管理 cc.Node 节点对象,请使用 {{#crossLink "NodePool"}}cc.NodePool{{/crossLink}} 代替 - * 因为 cc.pool 是面向类来设计的,而 cc.Node 中使用 Component 来进行组合,它的类永远都一样,实际却千差万别。 - * - * cc.pool 是一个单例对象,用作为对象缓存池。
- * 它可以帮助您提高游戏性能,适用于优化对象的反复创建和销毁
- * @class pool - * @deprecated !#en Please use cc.NodePool instead !#zh 请使用 cc.NodePool 代替 - */ -cc.pool = /** @lends cc.pool# */{ - _pool: {}, - - _releaseCB: function () { - this.release(); - }, - - _autoRelease: function (obj) { - var running = obj._running === undefined ? false : !obj._running; - cc.director.getScheduler().schedule(this._releaseCB, obj, 0, 0, 0, running); - }, - - /** - * !#en Put the obj in pool. - * !#zh 加入对象到对象池中。 - * @method putInPool - * @param {Object} obj - The need put in pool object. - * @example {@link utils/api/engine/docs/extensions/ccpool/putInPool.js} - */ - putInPool: function (obj) { - var cid = cc.js._getClassId(obj.constructor); - if (!cid) { - return; - } - if (!this._pool[cid]) { - this._pool[cid] = []; - } - // User implementation for disable the object - obj.unuse && obj.unuse(); - this._pool[cid].push(obj); - }, - - /** - * !#en Check if this kind of obj has already in pool. - * !#zh 检查对象池中是否有指定对象的存在。 - * @method hasObject - * @param {Object} objClass - The check object class. - * @returns {Boolean} If this kind of obj is already in pool return true,else return false. - */ - hasObject: function (objClass) { - var cid = cc.js._getClassId(objClass); - var list = this._pool[cid]; - if (!list || list.length === 0) { - return false; - } - return true; - }, - - /** - * !#en Remove the obj if you want to delete it. - * !#zh 移除在对象池中指定的对象。 - * @method removeObject - */ - removeObject: function (obj) { - var cid = cc.js._getClassId(obj.constructor); - if (cid) { - var list = this._pool[cid]; - if (list) { - for (var i = 0; i < list.length; i++) { - if (obj === list[i]) { - list.splice(i, 1); - } - } - } - } - }, - - /** - * !#en Get the obj from pool. - * !#zh 获取对象池中的指定对象。 - * @method getFromPool - * @returns {*} Call the reuse function an return the obj. - */ - getFromPool: function (objClass/*,args*/) { - if (this.hasObject(objClass)) { - var cid = cc.js._getClassId(objClass); - var list = this._pool[cid]; - _args.length = arguments.length - 1; - for (var i = 0; i < _args.length; i++) { - _args[i] = arguments[i+1]; - } - var obj = list.pop(); - // User implementation for re-enable the object - obj.reuse && obj.reuse.apply(obj, _args); - _args.length = 0; - return obj; - } - }, - - /** - * !#en Remove all objs in pool and reset the pool. - * !#zh 移除对象池中的所有对象,并且重置对象池。 - * @method drainAllPools - */ - drainAllPools: function () { - if (CC_JSB) { - for (var i in this._pool) { - for (var j = 0; j < this._pool[i].length; j++) { - var obj = this._pool[i][j]; - } - } - } - this._pool = {}; - } -}; \ No newline at end of file diff --git a/test/qunit/unit-es5/test-html-text-parser.js b/test/qunit/unit-es5/test-html-text-parser.js index 7750e6fff7..13f2c18c0c 100644 --- a/test/qunit/unit-es5/test-html-text-parser.js +++ b/test/qunit/unit-es5/test-html-text-parser.js @@ -2,7 +2,7 @@ largeModule('HtmlTextParser'); -var parser = new cc.HtmlTextParser(); +var parser = new cc._Test.HtmlTextParser(); test('Basic Test', function() {