Actionscript 3 AS3设置过滤区域的动画位置(位图数据)

Actionscript 3 AS3设置过滤区域的动画位置(位图数据),actionscript-3,filter,animated,Actionscript 3,Filter,Animated,我知道设置任意给定过滤器数量的动画很简单,但假设在舞台的特定区域(矩形)上有一个过滤器。 您将如何设置此过滤区域的位置动画(在两个区域之间),以便效果在舞台上移动?实现想到的效果的一种方法是将舞台内容绘制到位图数据,然后使用BitmapData.applyFilter()。applyFilter()用于指定sourceRect和destPoint。因此,在您的例子中,可以设置sourceRect属性的动画。在这种情况下,destPoint的x和y应该与sourceRect的x和y相同 下面是一个

我知道设置任意给定过滤器数量的动画很简单,但假设在舞台的特定区域(矩形)上有一个过滤器。
您将如何设置此过滤区域的位置动画(在两个区域之间),以便效果在舞台上移动?

实现想到的效果的一种方法是将舞台内容绘制到位图数据,然后使用BitmapData.applyFilter()。applyFilter()用于指定sourceRect和destPoint。因此,在您的例子中,可以设置sourceRect属性的动画。在这种情况下,destPoint的x和y应该与sourceRect的x和y相同

下面是一个工作示例:

package {
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;

    public class Main extends Sprite {

        public function Main():void {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            var bitmapData : BitmapData = new BitmapData(this.stage.stageWidth, this.stage.stageHeight);
            var sourceRectVelocity : Point = new Point(3, 2);
            var sourceRect : Rectangle = new Rectangle(50, 100, 200, 150);
            var bitmap : Bitmap = new Bitmap(bitmapData);

            // draw some random circles on the stage
            for (var i:int = 0; i < 100; i++) {
                this.graphics.beginFill((Math.floor(Math.random()*255) << 16) + (Math.floor(Math.random()*255) << 8) + Math.floor(Math.random()*255), 1);
                this.graphics.drawCircle(Math.random()*this.stage.stageWidth, Math.random()*this.stage.stageHeight, 50 + Math.random()*50);
            }

            this.addChild(bitmap);

            this.addEventListener(Event.ENTER_FRAME, function(event : Event):void {
                sourceRect.x = Math.min(Math.max(sourceRect.x + sourceRectVelocity.x, 0), bitmapData.width - sourceRect.width);
                sourceRect.y = Math.min(Math.max(sourceRect.y + sourceRectVelocity.y, 0), bitmapData.height - sourceRect.height);

                if (sourceRect.right >= bitmapData.width) {
                    sourceRectVelocity.x = -Math.abs(sourceRectVelocity.x);
                } else if (sourceRect.left <= 0) {
                    sourceRectVelocity.x = Math.abs(sourceRectVelocity.x);
                }

                if (sourceRect.bottom >= bitmapData.height) {
                    sourceRectVelocity.y = -Math.abs(sourceRectVelocity.y);
                } else if (sourceRect.top <= 0) {
                    sourceRectVelocity.y = Math.abs(sourceRectVelocity.y);
                }

                // clear the bitmap with white (not needed if the stage doesn't have any transparency)
                bitmapData.fillRect(bitmapData.rect, 0xffffff);

                // draw the stage to the bitmapData, but make sure the Bitmap display object showing the BitmapData isn't visible
                bitmap.visible = false;
                bitmapData.draw(stage);
                bitmap.visible = true;

                // apply greyscale filter
                bitmapData.applyFilter(bitmapData, sourceRect, new Point(sourceRect.x, sourceRect.y), new ColorMatrixFilter([0.3, 0.59, 0.11, 0, 0,0.3, 0.59, 0.11, 0, 0,0.3, 0.59, 0.11, 0, 0,0, 0, 0, 1, 0]));
            });
        }
    }
}
包{
导入flash.display.*;
导入flash.events.*;
进口闪光滤光片。*;
导入flash.geom.*;
公共类Main扩展了Sprite{
公共函数Main():void{
if(stage)init();
else addEventListener(Event.ADDED_TO_STAGE,init);
}
私有函数init(e:Event=null):void{
removeEventListener(Event.ADDED_TO_STAGE,init);
var bitmapData:bitmapData=新的bitmapData(this.stage.stageWidth,this.stage.stageHeight);
var sourceRectVelocity:点=新点(3,2);
var sourceRect:Rectangle=新矩形(50100200150);
变量位图:位图=新位图(bitmapData);
//在舞台上随机画一些圆圈
对于(变量i:int=0;i<100;i++){

this.graphics.beginll((Math.floor(Math.random()*255))您有一些代码示例吗?