我希望将 KineticJS 用作绘图画布,它在桌面浏览器上运行良好,但在移动浏览器上运行缓慢。现在,当鼠标移动并将新点设置为标记线时,我只是不断地在图层上调用 draw 。
在不失去绘图平滑度的情况下,我能做些什么来优化速度呢?
var stage;
var input;
var marker;
var points = [];
function initialize() {
stage = new Kinetic.Stage({
container: 'container',
width: $(window).width(),
height: $(window).height()
});
input = new Kinetic.Layer();
stage.add(input);
marker = new Kinetic.Line({
stroke: 'red',
strokeWidth: 16,
lineCap: 'round',
lineJoin: 'round'
});
input.add(marker);
stage.on('mousedown touchstart', handleMouseDown);
stage.on('mouseup touchend', handleMouseUp);
}
function handleMouseDown() {
points = [];
stage.on('mousemove touchmove', handleMouseMove);
}
function handleMouseMove() {
points.push(stage.getPointerPosition());
marker.setAttr('points', points);
input.draw();
}
function handleMouseUp() {
stage.off('mousemove touchmove');
}