旋转图像我有这样的小提琴:Kinetic.js:触摸
图像没有正确地旋转。 ,我使用的代码是:
var stage = new Kinetic.Stage({
container: 'd',
width: 300,
height: 300
});
var layer = new Kinetic.Layer();
var isDragging = false;
var refRotation = null;
var rect = new Kinetic.Rect({
x: 150,
y: 150,
width: 100,
height: 100,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
offset: [50, 50],
dragOnTop: true,
draggable: true,
dragBoundFunc: function (pos) {
var xd = 150 - pos.x ;
var yd = 150 - pos.y ;
var theta = Math.atan2(yd, xd);
var deg = theta * 180/Math.PI;
if (!isDragging) {
isDragging = true;
refRotation = deg;
} else {
var rotate = deg - refRotation;
rect.setRotationDeg(deg);
}
return {
x: this.getAbsolutePosition().x,
y: this.getAbsolutePosition().y
}
}
});
layer.add(RECT); stage.add(layer);
任何人都知道我的数学有什么问题?
---编辑---
与我想要的新feddle: http://jsfiddle.net/zk9cn/
我不认为你的数学没有错。它正确旋转。当你说错误时,它会做什么以及期望什么。我注意到的唯一的事情就是光标离矩形越近越好。但这是因为没有处理。如果在红色矩形边框上移动时旋转。它工作正常。 – 2013-02-19 04:25:15