Actionscript:如何使用矩阵旋转外部png图像?

时间:2010-08-25 05:50:22

标签: actionscript-3

好的,我有两个导入的代码片段。第一个微小的位是创建一个名为OBJECT_arrow的对象。它位于我的主要课程的主要功能中:

new OBJECT_arrow().CREATE(this,200,200);

实际上并不是那么重要。现在下一个是OBJECT_arrow类。它的作用是加载外部png图像并绘制它。

package
{
    import flash.net.URLRequest;
    import flash.display.*;
    import flash.system.*;
    import flash.events.*;
    import Math;
    public class OBJECT_arrow extends Sprite
    {
        public var X:Number = 0;    public var Y:Number = 0;
        public var DEPTH:int = 0 ;
        public var CONTAINER:Sprite = new Sprite();
        public var imageLoader:Loader = new Loader();
        public var image:URLRequest = new URLRequest ('ARROW.png');
        public function CREATE(CONTAINER:Sprite,X:Number,Y:Number):void
        {
            this.X = X;     imageLoader.x = this.X;
            this.Y = Y;     imageLoader.y = this.Y;
            this.CONTAINER = CONTAINER;
            CONTAINER.stage.addEventListener(Event.ENTER_FRAME,STEP);
            imageLoader.load(image);
            DRAW();
        }

        public function STEP(event:Event):void
        {
            DRAW();
        }

        public function DRAW():void 
        {
            addChild (imageLoader);
            (CONTAINER as MAIN).DRAW_LIST[(CONTAINER as MAIN).DRAW_LIST.length] = this;
            (CONTAINER as MAIN).DRAW_LIST[(CONTAINER as MAIN).DRAW_LIST.length] = DEPTH;
        }
    }
}

现在我知道旋转背后的数学,并且在我翻译之前知道要旋转,除了我根本不知道如何在as3中将变换应用到外部图像。

2 个答案:

答案 0 :(得分:1)

使用Loader加载图片时,它会存储为DisplayObject类型的对象。

如果您想要旋转它,只需设置rotation属性。

答案 1 :(得分:1)

要应用矩阵,可以使用DisplayObject的transform()方法。

您还应该查看BitmapData(原始图像数据)和Bitmap(用于保存BitmapData的DisplayObject)类。根据您尝试做的复杂程度,它们可能会更好地为您服务。具体来说,BitmapData将允许您在摆弄其位时锁定()图像。在你解锁()它之前,Flash不会渲染BitmapData,如果你做了大量的调整,这可能是一个很好的性能提升。

相关问题