Canvas 如何覆盖tick()以在多个阶段降低FPS

Canvas 如何覆盖tick()以在多个阶段降低FPS,canvas,html5-canvas,easeljs,createjs,Canvas,Html5 Canvas,Easeljs,Createjs,假设我们有两个阶段和Ticker.setFPS(30),我如何覆盖第二阶段的Ticker,使其达到15fps //以30fps为目标 Stage['GUI']=newcreatejs.Stage(GUI_画布); createjs.Ticker.useRAF=true; createjs.Ticker.setFPS(30); createjs.Ticker.addEventListener('tick',Stage['GUI']); //以15fps为目标 Stage['Background']

假设我们有两个阶段和
Ticker.setFPS(30)
,我如何覆盖第二阶段的Ticker,使其达到15fps

//以30fps为目标
Stage['GUI']=newcreatejs.Stage(GUI_画布);
createjs.Ticker.useRAF=true;
createjs.Ticker.setFPS(30);
createjs.Ticker.addEventListener('tick',Stage['GUI']);
//以15fps为目标
Stage['Background']=新的createjs.Stage(背景画布);
/*覆盖的股票代码在这里*/
createjs.Ticker.addEventListener('tick',Stage['Background']);
使用markE的解决方案解决

stage['background']=newcreatejs.stage(背景画布);
无功延迟=3;
var ticker=函数(参数){
如果(延迟===0){
延迟=-1;
stage['background'].update();
延迟=3;
}
延迟--;
};
createjs.Ticker.addEventListener('tick',Ticker);
获取目标FPS的另一种解决方案

stage['background']=newcreatejs.stage(背景画布);
var timestamp=new Date().getTime();
var ticker=函数(){
var now=new Date().getTime();
如果((现在-时间戳)>(1000/15)){
stage['background'].update();
时间戳=新日期().getTime();
}
};
createjs.Ticker.addEventListener('tick',Ticker);
由于EaselJS有一个(只有一个)中央自动售票机,用于发出“滴答”事件,因此您必须限制第二个滴答功能

要做到这一点,您只需设置一个倒计时延迟,并等待实际执行动画,直到倒计时达到0

// make tickGUI() the tick handler for stage['GUI']
createjs.Ticker.addEventListener('tick', tickGUI);

// make tickBackground() the tick handler for stage['Background']
createjs.Ticker.addEventListener('tick', tickBackground);


// tickGUI animates on every tick
function tickGUI(){
    // do your animating stuff for GUI now
}


// tickBackground has a "2 ticks=1 animation" throttle
var tickBackgroundDelay=1;

function tickBackground(){
    if(tickBackgroundDelay==0){

        // [optionally] turn off this ticker until you process your animation
        tickBackgroundDelay=-1;  

        // do your animating stuff for Background now

        // turn on this ticker with delay=1
        tickBackgroundDelay=1;
    }
    // countdown the delay ticker
    tickBackgroundDelay--;
}
由于EaselJS有一个(只有一个)发出“滴答”事件的中央滴答器,因此您必须限制第二个滴答功能

要做到这一点,您只需设置一个倒计时延迟,并等待实际执行动画,直到倒计时达到0

// make tickGUI() the tick handler for stage['GUI']
createjs.Ticker.addEventListener('tick', tickGUI);

// make tickBackground() the tick handler for stage['Background']
createjs.Ticker.addEventListener('tick', tickBackground);


// tickGUI animates on every tick
function tickGUI(){
    // do your animating stuff for GUI now
}


// tickBackground has a "2 ticks=1 animation" throttle
var tickBackgroundDelay=1;

function tickBackground(){
    if(tickBackgroundDelay==0){

        // [optionally] turn off this ticker until you process your animation
        tickBackgroundDelay=-1;  

        // do your animating stuff for Background now

        // turn on this ticker with delay=1
        tickBackgroundDelay=1;
    }
    // countdown the delay ticker
    tickBackgroundDelay--;
}

编辑我的答案为阶段['GUI']和阶段['Background']提供单独的勾号处理程序编辑我的答案为阶段['GUI']和阶段['Background']提供单独的勾号处理程序