簡體   English   中英

Actionscript 3.0 圍繞其中心點旋轉精靈

[英]Actionscript 3.0 Rotating a sprite around its center point

我在網上搜索並找到了這個應該旋轉和圖像的腳本,但我不確定如何使用,在哪里放置我希望我的精靈旋轉的度數。 另外,我得到一個錯誤。 1084:語法錯誤:在左括號之前需要標識符。 1084:語法錯誤:在左大括號之前需要右括號。

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

將 function 修復到此

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

代碼中的45是您要旋轉的度數,只需更改該值即可。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM