【问题标题】:Actionscript 3.0 Sprite Rotation Around Center ErrorActionscript 3.0 Sprite 围绕中心旋转错误
【发布时间】:2011-07-07 03:06:25
【问题描述】:

我在网上找到了这个动作脚本来围绕它的中心点旋转一个精灵,但是当我使用它时出现两个错误。 1084:语法错误:在左括号之前需要标识符。 1084: 语法错误:在 leftbrace 之前需要 rightparen。 另外,在 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;
}

【问题讨论】:

    标签: actionscript-3 sprite image-rotation


    【解决方案1】:

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

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

    到这里:

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

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

    要改进该函数并使其更易于重用,您可以将 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-22
      • 1970-01-01
      相关资源
      最近更新 更多