假设我们有 2 个阶段,并且Ticker.setFPS(30)
,我怎样才能覆盖第二阶段的代码让我们说 15fps?
// Targeting 30fps
Stage['GUI'] = new createjs.Stage(gui_canvas);
createjs.Ticker.useRAF = true;
createjs.Ticker.setFPS(30);
createjs.Ticker.addEventListener('tick', Stage['GUI']);
// Targeting 15fps
Stage['Background'] = new createjs.Stage(bg_canvas);
/* Overriding ticker goes here */
createjs.Ticker.addEventListener('tick', Stage['Background']);
使用markE的解决方案解决
stage['background'] = new createjs.Stage(bg_canvas);
var delay = 3;
var ticker = function(params){
if(delay===0){
delay = -1;
stage['background'].update();
delay = 3;
}
delay--;
};
createjs.Ticker.addEventListener('tick', ticker);
获得目标 FPS 的另一种解决方案
stage['background'] = new createjs.Stage(bg_canvas);
var timestamp = new Date().getTime();
var ticker = function(){
var now = new Date().getTime();
if ((now - timestamp) > (1000/15)){
stage['background'].update();
timestamp = new Date().getTime();
}
};
createjs.Ticker.addEventListener('tick', ticker);