Flex/ActionScript - rotate Sprite around its center

前端 未结 6 1627
一向
一向 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条回答
  •  Happy的楠姐
    2021-02-07 14:05

    An alternative solution is to put your object inside another View, move it so that your image's center is at the container's top-left corner, and then rotate the container.

    import spark.components.*;
    
    var myContainer:View = new View();
    var myImage:Image = new Image();
    
    myContainer.addElement(myImage);
    myImage.x = myImage.width / -2;
    myImage.y = myImage.height / -2;
    
    addElement(myContainer);
    
    myContainer.rotation = whateverAngle;
    

    One issue might be that the width of the image isn't know at the moment it is created, so you might want to find a way around that. (Hardcode it, or see if myImage.preliminaryWidth works)

提交回复
热议问题