@@ -93,7 +93,7 @@ var HashTimerEntry = function (timers, target, timerIndex, currentTimer, current
} ;
/*
* Light weight timer
* Light weight timer.
* @class Timer
*/
var Timer = cc . _Class . extend ( {
@@ -203,19 +203,27 @@ var getTargetId = function (target) {
} ;
/**
* <p>
* Scheduler is responsible of triggering the scheduled callbacks.<br/>
* You should not use NSTimer. Instead use this class.<br/>
* <br/>
* There are 2 different types of callbacks (selectors):<br/>
* - update callback: the 'update' callback will be called every frame. You can customize the priority.<br/>
* - custom callback: A custom callback will be called every frame, or with a custom interval of time<br/>
* <br/>
* The 'custom selectors' should be avoided when possible. It is faster, and consumes less memory to use the 'update callback'. *
* </p>
* !#en
* Scheduler is responsible of triggering the scheduled callbacks.<br/>
* You should not use NSTimer. Instead use this class.<br/>
* <br/>
* There are 2 different types of callbacks (selectors):<br/>
* - update callback: the 'update' callback will be called every frame. You can customize the priority.<br/>
* - custom callback: A custom callback will be called every frame, or with a custom interval of time<br/>
* <br/>
* The 'custom selectors' should be avoided when possible. It is faster,
* and consumes less memory to use the 'update callback'. *
* !#zh
* Scheduler 是负责触发回调函数的类。<br/>
* 通常情况下,建议使用 cc.director.getScheduler() 来获取系统定时器。<br/>
* 有两种不同类型的定时器:<br/>
* - update 定时器:每一帧都会触发。您可以自定义优先级。<br/>
* - 自定义定时器:自定义定时器可以每一帧或者自定义的时间间隔触发。<br/>
* 如果希望每帧都触发,应该使用 update 定时器,使用 update 定时器更快,而且消耗更少的内存。
*
* @class Scheduler
*/
cc . Scheduler = cc . _Class . extend ( /** @lends cc.Scheduler# */ {
cc . Scheduler = cc . _Class . extend ( {
_timeScale : 1.0 ,
//_updates : null, //_updates[0] list of priority < 0, _updates[1] list of priority == 0, _updates[2] list of priority > 0,
@@ -342,14 +350,18 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
//-----------------------public method-------------------------
/**
* <p>
* Modifies the time of all scheduled callbacks.<br/>
* You can use this property to create a 'slow motion' or 'fast forward' effect.<br/>
* Default is 1.0. To create a 'slow motion' effect, use values below 1.0.<br/>
* To create a 'fast forward' effect, use values higher than 1.0.<br/>
* @warning It will affect EVERY scheduled selector / action.
* </p>
*
* !#en
* Modifies the time of all scheduled callbacks.<br/>
* You can use this property to create a 'slow motion' or 'fast forward' effect.<br/>
* Default is 1.0. To create a 'slow motion' effect, use values below 1.0.<br/>
* To create a 'fast forward' effect, use values higher than 1.0.<br/>
* Note: It will affect EVERY scheduled selector / action.
* !#zh
* 设置时间间隔的缩放比例。<br/>
* 您可以使用这个方法来创建一个 “slow motion(慢动作)” 或 “fast forward(快进)” 的效果。<br/>
* 默认是 1.0。要创建一个 “slow motion(慢动作)” 效果,使用值低于 1.0。<br/>
* 要使用 “fast forward(快进)” 效果,使用值大于 1.0。<br/>
* 注意:它影响该 Scheduler 下管理的所有定时器。
* @method setTimeScale
* @param {Number} timeScale
*/
@@ -358,7 +370,8 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* Returns time scale of scheduler.
* !#en Returns time scale of scheduler.
* !#zh 获取时间间隔的缩放比例。
* @method getTimeScale
* @return {Number}
*/
@@ -367,7 +380,8 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* 'update' the scheduler. (You should NEVER call this method, unless you know what you are doing.)
* !#en 'update' the scheduler. (You should NEVER call this method, unless you know what you are doing.)
* !#zh update 调度函数。(不应该直接调用这个方法,除非完全了解这么做的结果)
* @method update
* @param {Number} dt delta time
*/
@@ -454,6 +468,7 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* !#en
* <p>
* The scheduled method will be called every 'interval' seconds.</br>
* If paused is YES, then it won't be called until it is resumed.<br/>
@@ -462,10 +477,20 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
* repeat let the action be repeated repeat + 1 times, use cc.macro.REPEAT_FOREVER to let the action run continuously<br/>
* delay is the amount of time the action will wait before it'll start<br/>
* </p>
* !#zh
* 指定回调函数,调用对象等信息来添加一个新的定时器。</br>
* 当时间间隔达到指定值时,设置的回调函数将会被调用。</br>
* 如果 paused 值为 true,那么直到 resume 被调用才开始计时。</br>
* 如果 interval 值为 0,那么回调函数每一帧都会被调用,但如果是这样,
* 建议使用 scheduleUpdateForTarget 代替。</br>
* 如果回调函数已经被定时器使用,那么只会更新之前定时器的时间间隔参数,不会设置新的定时器。<br/>
* repeat 值可以让定时器触发 repeat + 1 次,使用 cc.macro.REPEAT_FOREVER
* 可以让定时器一直循环触发。<br/>
* delay 值指定延迟时间,定时器会在延迟指定的时间之后开始计时。
* @method scheduleCallbackForTarget
* @deprecated since v3.4 please use .schedule
* @param {Object} target
* @param {f unction} callback_fn
* @param {F unction} callback_fn
* @param {Number} interval
* @param {Number} repeat
* @param {Number} delay
@@ -478,7 +503,8 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* The schedule
* !#en The schedule
* !#zh 定时器
* @method schedule
* @param {Function} callback
* @param {Object} target
@@ -538,7 +564,12 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* Schedules the update callback for a given target, the callback will be invoked every frame after schedule started
* !#en
* Schedules the update callback for a given target,
* the callback will be invoked every frame after schedule started.
* !#zh
* 使用指定的优先级为指定的对象设置 update 定时器。
* update 定时器每一帧都会被触发。优先级的值越低,定时器被触发的越早。
* @method scheduleUpdate
* @param {Object} target
* @param {Number} priority
@@ -561,9 +592,13 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
}
} ,
/**
/**
* !#en
* Unschedules a callback for a callback and a given target.
* If you want to unschedule the "update", use `unscheudleUpdate()`
* !#zh
* 根据指定的回调函数和调用对象。
* 如果需要取消 update 定时器,请使用 unscheudleUpdate()。
* @method unschedule
* @param {Function} callback The callback to be unscheduled
* @param {Object} target The target bound to the callback.
@@ -606,7 +641,8 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* Unschedules the update callback for a given target
* !#en Unschedules the update callback for a given target.
* !#zh 取消指定对象的 update 定时器。
* @method unscheduleUpdate
* @param {Object} target The target to be unscheduled.
*/
@@ -626,8 +662,10 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* !#en
* Unschedules all scheduled callbacks for a given target.
* This also includes the "update" callback.
* !#zh 取消指定对象的所有定时器,包括 update 定时器。
* @method unscheduleAllForTarget
* @param {Object} target The target to be unscheduled.
*/
@@ -659,18 +697,26 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
this . unscheduleUpdate ( target ) ;
} ,
/**
* Unschedules all scheduled callbacks from all targets including the system callbacks.
/**
* !#en
* Unschedules all scheduled callbacks from all targets including the system callbacks.<br/>
* You should NEVER call this method, unless you know what you are doing.
* !#zh
* 取消所有对象的所有定时器,包括系统定时器。<br/>
* 不用调用此函数,除非你确定你在做什么。
* @method unscheduleAll
*/
unscheduleAll : function ( ) {
this . unscheduleAllWithMinPriority ( cc . Scheduler . PRIORITY _SYSTEM ) ;
} ,
/**
* Unschedules all callbacks from all targets with a minimum priority.
/**
* !#en
* Unschedules all callbacks from all targets with a minimum priority.<br/>
* You should only call this with `PRIORITY_NON_SYSTEM_MIN` or higher.
* !#zh
* 取消所有优先级的值大于指定优先级的定时器。<br/>
* 你应该只取消优先级的值大于 PRIORITY_NON_SYSTEM_MIN 的定时器。
* @method unscheduleAllWithMinPriority
* @param {Number} minPriority The minimum priority of selector to be unscheduled. Which means, all selectors which
* priority is higher than minPriority will be unscheduled.
@@ -719,16 +765,17 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* Checks whether a callback for a given target is scheduled.
* !#en Checks whether a callback for a given target is scheduled.
* !#zh 检查指定的回调函数和回调对象组合是否存在定时器。
* @method isScheduled
* @param {Function|String} key The callback to check.
* @param {Function} callback The callback to check.
* @param {Object} target The target of the callback.
* @return {Boolean} True if the specified callback is invoked, false if not.
*/
isScheduled : function ( key , target ) {
isScheduled : function ( callback , target ) {
//key, target
//selector, target
cc . assert ( key , "Argument key must not be empty" ) ;
cc . assert ( callback , "Argument callback must not be empty" ) ;
cc . assert ( target , "Argument target must be non-nullptr" ) ;
var element = this . _hashForUpdates [ getTargetId ( target ) ] ;
@@ -744,7 +791,7 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
for ( var i = 0 ; i < timers . length ; ++ i ) {
var timer = timers [ i ] ;
if ( key === timer . getKey ( ) ) {
if ( callback === timer . getKey ( ) ) {
return true ;
}
}
@@ -753,11 +800,12 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* <p>
* Pause all selectors from all targets.<br/>
* You should NEVER call this method, unless you know what you are doing.
* </p>
*
* !#en
* Pause all selectors from all targets.<br/>
* You should NEVER call this method, unless you know what you are doing.
* !#zh
* 暂停所有对象的所有定时器。<br/>
* 不要调用这个方法,除非你知道你正在做什么。
* @method pauseAllTargets
*/
pauseAllTargets : function ( ) {
@@ -765,8 +813,12 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* !#en
* Pause all selectors from all targets with a minimum priority. <br/>
* You should only call this with kCCPriorityNonSystemMin or higher.
* !#zh
* 暂停所有优先级的值大于指定优先级的定时器。<br/>
* 你应该只暂停优先级的值大于 PRIORITY_NON_SYSTEM_MIN 的定时器。
* @method pauseAllTargetsWithMinPriority
* @param {Number} minPriority
*/
@@ -821,8 +873,12 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* !#en
* Resume selectors on a set of targets.<br/>
* This can be useful for undoing a call to pauseAllCallbacks.
* !#zh
* 恢复指定数组中所有对象的定时器。<br/>
* 这个函数是 pauseAllCallbacks 的逆操作。
* @method resumeTargets
* @param {Array} targetsToResume
*/
@@ -836,11 +892,14 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* <p>
* Pauses the target.<br/>
* All scheduled selectors/update for a given target won't be 'ticked' until the target is resumed.<br/>
* If the target is not present, nothing happens.
* </p>
* !#en
* Pauses the target.<br/>
* All scheduled selectors/update for a given target won't be 'ticked' until the target is resumed.<br/>
* If the target is not present, nothing happens.
* !#zh
* 暂停指定对象的定时器。<br/>
* 指定对象的所有定时器都会被暂停。<br/>
* 如果指定的对象没有定时器,什么也不会发生。
* @method pauseTarget
* @param {Object} target
*/
@@ -864,9 +923,14 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* !#en
* Resumes the target.<br/>
* The 'target' will be unpaused, so all schedule selectors/update will be 'ticked' again.<br/>
* If the target is not present, nothing happens.
* !#zh
* 恢复指定对象的所有定时器。<br/>
* 指定对象的所有定时器将继续工作。<br/>
* 如果指定的对象没有定时器,什么也不会发生。
* @method resumeTarget
* @param {Object} target
*/
@@ -892,7 +956,8 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* Returns whether or not the target is paused
* !#en Returns whether or not the target is paused.
* !#zh 返回指定对象的定时器是否暂停了。
* @method isTargetPaused
* @param {Object} target
* @return {Boolean}
@@ -915,11 +980,14 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* <p>
* Schedules the 'update' callback_fn for a given target with a given priority.<br/>
* The 'update' callback_fn will be called every frame.<br/>
* The lower the priority, the earlier it is called.
* </p>
* !#en
* Schedules the 'update' callback_fn for a given target with a given priority.<br/>
* The 'update' callback_fn will be called every frame.<br/>
* The lower the priority, the earlier it is called.
* !#zh
* 为指定对象设置 update 定时器。<br/>
* update 定时器每一帧都会被调用。<br/>
* 优先级的值越低,越早被调用。
* @method scheduleUpdateForTarget
* @deprecated since v3.4 please use .scheduleUpdate
* @param {Object} target
@@ -933,10 +1001,12 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* <p>
* Unschedule a callback function for a given target.<br/>
* If you want to unschedule the "update", use unscheudleUpdateForTarget.
* </p>
* !#en
* Unschedule a callback function for a given target.<br/>
* If you want to unschedule the "update", use unscheudleUpdateForTarget.
* !#zh
* 根据指定的回调函数和调用对象对象取消相应的定时器。<br/>
* 如果需要取消 update 定时器,请使用 unscheudleUpdateForTarget()。
* @method unscheduleCallbackForTarget
* @deprecated since v3.4 please use .unschedule
* @param {Object} target
@@ -949,7 +1019,8 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* Unschedules the update callback function for a given target
* !#en Unschedules the update callback function for a given target.
* !#zh 取消指定对象的所有定时器。
* @method unscheduleUpdateForTarget
* @param {Object} target
* @deprecated since v3.4 please use .unschedule
@@ -961,7 +1032,10 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* Unschedules all function callbacks for a given target. This also includes the "update" callback function.
* !#en
* Unschedules all function callbacks for a given target.<br/>
* This also includes the "update" callback function.
* !#zh 取消指定对象的所有定时器,包括 update 定时器。
* @method unscheduleAllCallbacksForTarget
* @deprecated since v3.4 please use unscheduleAllForTarget
* @param {Object} target
@@ -972,10 +1046,12 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* <p>
* Unschedules all function callbacks from all targets. <br/>
* You should NEVER call this method, unless you know what you are doing.
* </p>
* !#en
* Unschedules all function callbacks from all targets. <br/>
* You should NEVER call this method, unless you know what you are doing.
* !#zh
* 取消所有对象的所有定时器。<br/>
* 不要调用这个方法,除非你知道你正在做什么。
* @method unscheduleAllCallbacks
* @deprecated since v3.4 please use .unscheduleAllWithMinPriority
*/
@@ -985,10 +1061,12 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ,
/**
* <p>
* Unschedules all function callbacks from all targets with a minimum priority.<br/>
* You should only call this with kCCPriorityNonSystemMin or higher.
* </p>
* !#en
* Unschedules all function callbacks from all targets with a minimum priority.<br/>
* You should only call this with kCCPriorityNonSystemMin or higher.
* !#zh
* 取消所有优先级的值大于指定优先级的所有对象的所有定时器。<br/>
* 你应该只暂停优先级的值大于 PRIORITY_NON_SYSTEM_MIN 的定时器。
* @method unscheduleAllCallbacksWithMinPriority
* @deprecated since v3.4 please use .unscheduleAllWithMinPriority
* @param {Number} minPriority
@@ -1000,7 +1078,8 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
} ) ;
/**
* Priority level reserved for system services.
* !#en Priority level reserved for system services.
* !#zh 系统服务的优先级。
* @property PRIORITY_SYSTEM
* @type {Number}
* @static
@@ -1008,7 +1087,8 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
cc . Scheduler . PRIORITY _SYSTEM = ( - 2147483647 - 1 ) ;
/**
* Minimum priority level for user scheduling.
* !#en Minimum priority level for user scheduling.
* !#zh 用户调度最低优先级。
* @property PRIORITY_NON_SYSTEM
* @type {Number}
* @static