Javascript 为什么Raphael.js的动画坐标不正确?

Javascript 为什么Raphael.js的动画坐标不正确?,javascript,raphael,Javascript,Raphael,我尝试在Raphael.js中制作一个简单的动画,其中paper.text对象从当前位置移动到另一个位置。以下是我的一些代码(太多了,无法全部发布): 以下是上述代码中引用的字母对象: function Letter(args) { this.letter = args.letter || "A"; this.correct = args.correct || false; this.transformation = args.transformation || "";

我尝试在Raphael.js中制作一个简单的动画,其中paper.text对象从当前位置移动到另一个位置。以下是我的一些代码(太多了,无法全部发布):

以下是上述代码中引用的字母对象:

function Letter(args)
{
    this.letter = args.letter || "A";
    this.correct = args.correct || false;
    this.transformation = args.transformation || "";
    this.initX = args.x || 0;
    this.initY = args.y || 0;
    this.path = null;
}

Letter.prototype.buildPath = function()
{
    this.path = paper.text(this.initX, this.initY, this.letter);
    if(this.transformation)
    {
        this.path.transform(this.transformation);
    }
    return this;
};
问题是我正在打印
getSongPosition
返回的
x
y
值,它们是正确的,但是动画方法将我的文本对象发送到屏幕外的某个位置。我还尝试将动画属性设置为
{x:0,y:0}
,但仍然得到相同的结果。如果有必要,我可以发布更多的代码

任何帮助都将不胜感激

更新1: 我的程序的一部分要求我能够将对象移动到特定的坐标。其中一些对象将旋转,而其他对象将不旋转,因此我写了以下内容:

Letter.prototype.getMoveTransform = function(x, y)
{
    var bbox = this.path.getBBox(true);
    var dx = x - bbox.x;
    var dy = y - bbox.y;
    return "T" + dx + "," + dy + (this.transformation == null ? "" : this.transformation);
};
我相信这是我问题的根源。此函数用于生成将旋转对象移动到(x,y)所需的变换。我不确定为什么我必须在每个动画上重新旋转对象

更新2: 我总算解决了我的问题。我会发布我的解决方案,但我不明白为什么这些方法一开始就有效/不再有效。

this.path.getBBox(true);应该是this.path.getBBox()或this.path.getBBox(false)


每次计算dx和dy时,都需要变换位置。为了帮助您,如果您可以使用JSFIDLE重新创建代码的动画部分,这将非常有用。netI已经尝试在JSFIDLE上重现我的问题,但我不能。我相信我已经找到了问题的根源,所以我会更新我的问题。拉斐尔不记得你以前的变换,当你做一个新的变换时,我不认为,你必须满足自己之前的任何变换。实际上,我可以通过将
dx=x-bbox.x
更改为
dx=x-bbox.x-bbox.width/2
使我的动画正常工作。
Letter.prototype.getMoveTransform = function(x, y)
{
    var bbox = this.path.getBBox(true);
    var dx = x - bbox.x;
    var dy = y - bbox.y;
    return "T" + dx + "," + dy + (this.transformation == null ? "" : this.transformation);
};