Flex/ActionScript - rotate Sprite around its center

前端 未结 6 1622
一向
一向 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 13:51

    If you want to rotate around the center, merely center the asset inside your sprite by setting the internal assets x and y to half of the width and height of the asset. This swill center your content and allow it to rotate around a center point.

    An example of runtime loaded assets is as follows:

    var loader:Loader = new Loader():
    var request:URLRequest = new URLRequest(path/to/asset.ext);
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _onLoaderComplete);
    loader.load(request);
    
    private function _onLoaderComplete(e:Event):void
    {
        var mc:MovieClip = e.target.content as MovieClip;
        mc.x = -mc.width * 0.5;
        mc.y = -mc.height * 0.5;
        mc.rotation = 90;
        addChild(mc);
    }
    

提交回复
热议问题