AS3: Getting the scale of a Matrix object

前端 未结 3 1566
余生分开走
余生分开走 2021-01-16 08:49

Most often, questions are asked about how to scale a DisplayObject, and the answer is usually to use a Matrix.

My question is, how to you GET the scale of a Matrix (

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-16 09:28

    you have access to the matrix object's a and d public properties, which represent the scaling of the x-axis and y-axis respectively:

    package
    {
    //Imports
    import flash.display.Sprite;
    import flash.geom.Matrix;
    import flash.display.Shape;
    
    //Class
    public class Test extends Sprite
        {
        //Constructor
        public function Test()
            {       
            var sh:Shape = new Shape();
            sh.graphics.beginFill(0xFF0000, 1.0);
            sh.graphics.drawRect(0, 0, 100, 100);
            sh.graphics.endFill();
    
            var scaleMatrix:Matrix = new Matrix();
            scaleMatrix.scale(4, 6);
    
            sh.transform.matrix = scaleMatrix;
    
            addChild(sh);
    
            trace("Matrix X Scale: " + scaleMatrix.a, "\nMatrix Y Scale: " + scaleMatrix.d);
            }
        }
    }
    
    // Matrix X Scale: 4 
    // Matrix Y Scale: 6
    

提交回复
热议问题