我想知道为什么这个简单的球移动代码在 IE 和 Chrome 中运行流畅,而在 Firefox 中它看起来很慢,尽管它保持相同的 FPS 速率。
我需要做什么才能在所有浏览器中实现相同的平滑移动?
var canvas,canvasContext,
ball,txt_shadow,txt_fps,
speed,angle;
function init() {
canvas = document.getElementById("canvas");
canvasContext = canvas.getContext("2d");
canvas.width=window.innerWidth;
canvas.height=window.innerHeight;
stage = new createjs.Stage(canvas);
stage.autoClear = true;
txt_shadow= new createjs.Shadow("black", 1, 1, 0);
ball = new createjs.Shape();
ball.graphics.beginFill("red").drawCircle(0, 0, 40);
txt_fps = new createjs.Text("", "18px Arial", "white");
txt_fps.shadow=txt_shadow;
txt_fps.x=canvas.width/2;txt_fps.y=100;
stage.addChild(txt_fps,ball);
ball.x=canvas.width/2;ball.y=canvas.height/2;
angle=Math.random()*360;
speed=8;
createjs.Ticker.addListener(window);
createjs.Ticker.setFPS(60);
}
function tick() {
fps=createjs.Ticker.getMeasuredFPS();
txt_fps.text=Math.round(fps);
ball.x += Math.sin(angle*(Math.PI/-180))*speed;
ball.y += Math.cos(angle*(Math.PI/-180))*speed;
if (ball.y<0 || ball.x<0 || ball.x>canvas.width || ball.y>canvas.height) {
angle+=45;
}
stage.update();
}