Scaling from the center in flash

耗尽温柔 提交于 2019-12-07 09:20:08

问题


I am using flash (AS3) and have a dynamic movie clip that I want to scale up or down using a slider bar. I have this working very well using the scaleX and scaleY functions.

The only trouble is that these scale from the left hand side of the document and I would like it to be scaled from the center

Any help is appreciated.


回答1:


function scaleFromCenter(dis:*, sX:Number, sY:Number):void
{
    var prevW:Number = dis.width;
    var prevH:Number = dis.height;
    dis.scaleX = sX;
    dis.scaleY = sY;
    dis.x += (prevW - dis.width) / 2;
    dis.y += (prevH - dis.height) / 2;
}

scaleFromCenter(yourMovieClip, 0.3, 0.3);

..

Or have a look at Greensocks TweenMax/AutoFitArea

http://www.greensock.com/autofitarea/

Very powerful and easy to use.




回答2:


In order to scale / Rotate from the center of the object you need to do the following

  1. Translate the object to 0,0.
  2. Scale / Rotate
  3. Translate it back to its original x,y.

Here is a piece of code that does it.

private function scaleInPosition(dis:Sprite,sX:Number,sY:Number):void
{
    var posX:Number = dis.x;
    var posY:Number = dis.y;
    dis.x =dis.y = 0;
    dis.scaleX = sX;
    dis.scaleY = sY;
    dis.x = posX;
    dis.y = posY;
}



回答3:


Simply create the object that you're scaling with it's 0,0 registration crosshair at the centre.



来源:https://stackoverflow.com/questions/8574943/scaling-from-the-center-in-flash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!