【发布时间】:2013-08-07 17:38:07
【问题描述】:
我希望将 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');
}
【问题讨论】: