Flex/ActionScript - rotate Sprite around its center

前端 未结 6 1521
一向
一向 2021-02-07 13:15

I have created a Sprite in Actionscript and rendered it to a Flex Canvas. Suppose:

var fooShape:Sprite = new FooSpriteSubclass();

fooCanvas.rawChildren.addChild         


        
6条回答
  •  无人共我
    2021-02-07 14:18

    Didn't have much luck with the other examples. This one worked for me. I used it on a UIComponent.

    http://www.selikoff.net/2010/03/17/solution-to-flex-image-rotation-and-flipping-around-center/

    private static function rotateImage(image:Image, degrees:Number):void {
    // Calculate rotation and offsets
    var radians:Number = degrees * (Math.PI / 180.0);
    var offsetWidth:Number = image.contentWidth/2.0;
    var offsetHeight:Number =  image.contentHeight/2.0;
    
    // Perform rotation
    var matrix:Matrix = new Matrix();
    matrix.translate(-offsetWidth, -offsetHeight);
    matrix.rotate(radians);
    matrix.translate(+offsetWidth, +offsetHeight);
    matrix.concat(image.transform.matrix);
    image.transform.matrix = matrix;
    

    }

提交回复
热议问题