Skip to content

Commit

Permalink
fix: ticker.start(true) use raf when fps >= 60
Browse files Browse the repository at this point in the history
  • Loading branch information
06wj committed Apr 26, 2017
1 parent 5d81936 commit 7d5e1a0
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/util/Ticker.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ var Ticker = Class.create(/** @lends Ticker.prototype */{
window[Hilo.browser.jsVendor + 'RequestAnimationFrame'];

var runLoop;
if(useRAF && raf){
var tick = function(){
self._tick();
};
if(useRAF && raf && interval < 17){
this._useRAF = true;
runLoop = function(){
self._intervalId = setTimeout(runLoop, interval);
raf(tick);
self._intervalId = raf(runLoop);
self._tick();
};
}else{
runLoop = function(){
Expand All @@ -71,6 +69,7 @@ var Ticker = Class.create(/** @lends Ticker.prototype */{
};
}

this._paused = false;
runLoop();
},

Expand All @@ -83,9 +82,17 @@ var Ticker = Class.create(/** @lends Ticker.prototype */{
* 停止定时器。
*/
stop: function(){
clearTimeout(this._intervalId);
if(this._useRAF){
var cancelRAF = window.cancelAnimationFrame ||
window[Hilo.browser.jsVendor + 'CancelAnimationFrame'];
cancelRAF(this._intervalId);
}
else{
clearTimeout(this._intervalId);
}
this._intervalId = null;
this._lastTime = 0;
this._paused = true;
},

/**
Expand Down

0 comments on commit 7d5e1a0

Please sign in to comment.