1
我在Javascript和動力學新的,我需要實現一個函數來繪製一個Kinetics.Js繪製freehandline一個freehandline。我發現這個例子,但只適用於開始和終點。我會實時通過遵循的MousePointer畫......我不知道如何改變功能或推一些新的座標...Kinetic.js - 通過以下的MousePointer
你有一個想法?
var moving = false;
function createLine() {
line = new Kinetic.Line({
points: [0, 0, 0, 0],
stroke: "red",
strokeWidth: 2,
id: 'line',
name: 'line',
draggable: true
});
lineLayer.add(line);
addHoverEffect(lineLayer, line);
lineLayer.draw();
}
function drawLine() {
stage.on("mousedown touchstart", function() {
createLine();
if (moving) {
moving = false;
lineLayer.draw();
} else {
var pos = stage.getPointerPosition();
//start point and end point are the same
line.getPoints()[0].x = parseInt(pos.x);
line.getPoints()[0].y = parseInt(pos.y);
line.getPoints()[1].x = parseInt(pos.x);
line.getPoints()[1].y = parseInt(pos.y);
moving = true;
lineLayer.drawScene();
}
});
stage.on("mousemove touchmove", function() {
if (moving) {
var pos = stage.getPointerPosition();
line.getPoints()[1].x = parseInt(pos.x);
line.getPoints()[1].y = parseInt(pos.y);
moving = true;
lineLayer.drawScene();
}
});
stage.on("mouseup touchend", function() {
moving = false;
removeLineDrawEvents();
});
}
當我在Chrome中打開你的小提琴,我得到'遺漏的類型錯誤:無法對「CanvasRenderingContext2D」執行「補」:參數1(「[對象CanvasRenderingContext2D ]')不是有效的枚舉value.' – 2014-04-03 16:14:17
最後,如果它也適用於觸摸屏(如果它在所有工作),你可以將其調整到我的問題:http://stackoverflow.com/q/22423791/ 562769 – 2014-04-03 16:15:40