0
私はビットマップデータを保持するスプライトを持っています。 スライダを使って画像のサイズを変更できるようにしたいと考えています。 私は下のコードを使用しています。スケーリングが加法的であるため、画像が完全に消えてしまうという問題があります。AS3:スライダを変更したときのマトリックス付きスプライトのスケーリング?
私は非加算的な方法で縮尺を変えなければならないことを理解しています。
私が通過しようとした:
var m:Matrix = userImageCopy.transform.matrix;
userImageCopyは、元画像を保持しています。これはスケーリングに役立ちましたが、スケーリングが開始されるたびにuserImageがuserImageCopyの位置にジャンプしました。
助けが必要ですか?
function onSliderChange(evt:Event):void
{
trace(evt.target.value);
//this will create a point object at the center of the display object
var ptRotationPoint:Point = new Point(userImage.x + userImage.width/2,userImage.y + userImage.height/2);
//call the function and pass in the object to be rotated, the amount to scale X and Y (sx, sy), and the point object we created
scaleFromCenter(userImage, evt.target.value, evt.target.value, ptRotationPoint);
}
private function scaleFromCenter(ob:*, sx:Number, sy:Number, ptScalePoint:Point)
{
var m:Matrix = userImage.transform.matrix;
m.tx -= ptScalePoint.x;
m.ty -= ptScalePoint.y;
m.scale(sx, sy);
m.tx += ptScalePoint.x;
m.ty += ptScalePoint.y;
ob.transform.matrix = m;
}