Actionscript 3 Actionscript 3.0精灵围绕中心旋转错误

Actionscript 3 Actionscript 3.0精灵围绕中心旋转错误,actionscript-3,sprite,image-rotation,Actionscript 3,Sprite,Image Rotation,我在网上找到了这个动作脚本,它可以使精灵围绕其中心点旋转,但我在使用它时遇到了两个错误1084:语法错误:在leftparen之前需要标识符。1084:语法错误:左括号前应为rightparen。 另外,我是否要输入精灵旋转的角度来代替角度度 var point:Point=new Point(spr_box.x+spr_box.width/2, spr_box.y+spr_box.height/2); rotateAroundCenter(spr_box,45); function

我在网上找到了这个动作脚本,它可以使精灵围绕其中心点旋转,但我在使用它时遇到了两个错误1084:语法错误:在leftparen之前需要标识符。1084:语法错误:左括号前应为rightparen。 另外,我是否要输入精灵旋转的角度来代替角度度

var point:Point=new Point(spr_box.x+spr_box.width/2, spr_box.y+spr_box.height/2);
    rotateAroundCenter(spr_box,45);

function rotateAroundCenter (ob:*, angleDegrees) {
    var m:Matrix=ob.transform.matrix;
    m.tx -= point.x;
    m.ty -= point.y;
    m.rotate (angleDegrees*(Math.PI/180));
    m.tx += point.x;
    m.ty += point.y;
    ob.transform.matrix=m;
}

要消除语法错误,请更改此行:

m.旋转(角度度*(数学PI/180))

为此:

m.rotate=(angleDegrees*(Math.PI/180))

从外观上看,您应该使用angleDegrees作为您想要的精灵位移角度

为了改进该函数并使其更易于重用,可以将
点的声明移动到函数内部

大概是这样的:

function rotateAroundCenter(ob:DisplayObject, angleDegrees:Number) : void {
    var point:Point=new Point(ob.x + ob.width / 2, ob.y + ob.height / 2);

    var m:Matrix = ob.transform.matrix;
    m.tx -= point.x;
    m.ty -= point.y;
    m.rotate = (angleDegrees*(Math.PI/180));
    m.tx += point.x;
    m.ty += point.y;
    ob.transform.matrix = m;
}