Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions cocos2d/core/CCScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,9 @@ cc.inject({
this._useDelay = (this._delay > 0);
this._repeat = repeat;
this._runForever = (this._repeat === cc.REPEAT_FOREVER);
this._timesExecuted = 0;
return true;
},
/**
* @return {Number} returns interval of timer
*/
getInterval : function(){return this._interval;},
/**
* @param {Number} interval set interval in seconds
*/
setInterval : function(interval){this._interval = interval;},

/**
* triggers the timer
Expand All @@ -222,22 +215,20 @@ cc.inject({
} else {//advanced usage
if (this._useDelay) {
if (this._elapsed >= this._delay) {
this._timesExecuted += 1; // important to increment before call trigger
this.trigger();

this._elapsed -= this._delay;
this._timesExecuted += 1;
this._useDelay = false;
}
} else {
if (this._elapsed >= this._interval) {
this._timesExecuted += 1; // important to increment before call trigger
this.trigger();

this._elapsed = 0;
this._timesExecuted += 1;
}
}

if (this._callback && !this._runForever && this._timesExecuted > this._repeat)
if (this._callback && this.isExhausted())
this.cancel();
}
}
Expand All @@ -260,6 +251,10 @@ cc.inject({
cancel: function () {
//override
this._scheduler.unschedule(this._callback, this._target);
},

isExhausted: function () {
return !this._runForever && this._timesExecuted > this._repeat;
}
}, CallbackTimer.prototype);

Expand Down Expand Up @@ -609,9 +604,9 @@ cc.Scheduler = cc.Class.extend(/** @lends cc.Scheduler# */{
} else {
for (i = 0; i < element.timers.length; i++) {
timer = element.timers[i];
if (callback === timer._callback) {
if (!timer.isExhausted() && callback === timer._callback) {
cc.log(cc._LogInfos.Scheduler_scheduleCallbackForTarget, timer.getInterval().toFixed(4), interval.toFixed(4));
timer._interval = interval;
timer.initWithCallback(this, callback, target, interval, repeat, delay, key);
return;
}
}
Expand Down