0

スプライトを中心点を中心に回転させるアクション スクリプトをオンラインで見つけましたが、使用すると 2 つのエラーが発生します。1084: 構文エラー: 左括弧の前に識別子が必要です。1084: 構文エラー: 左括弧の前に右括弧が必要です。 また、angleDegreesの代わりに、スプライトを回転させたい角度を入れますか?

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;
}
4

1 に答える 1

0

構文エラーを取り除くには、次の行を変更します。

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

これに:

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

見た目では、スプライトに必要な変位の角度としてangleDegreesを使用する必要があります。

その関数を改善し、再利用しやすくするためにpoint、関数内の宣言を移動することができます。

このようなもの:

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;
}
于 2011-07-06T18:53:50.010 に答える