0

我一直在使用类似于 Adob​​e 的标准位移映射过滤器和许多其他示例创建放大镜类:http: //help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7da2.html

该过滤器在应用程序级别使用,因此它过滤所有内容,并且有大量可以在屏幕上拖动、旋转和缩放的图像元素,当通过此过滤器时,它会放大它们。我还打算添加更多功能以允许拖动过滤器。

过滤器按预期工作,放大通过它的所有内容。奇怪的是,每当图像被拖动到​​屏幕的顶部或左边缘之外时,过滤器会在该方向浮动,它在图像完全离开屏幕之前所花费的距离(即:如果图片 500,过滤器会向左浮动 500 像素像素宽被拉出屏幕左侧。)

我正在使用一个 enterFrame 监听器来不断更新它的位置,它的工作原理如下:

private function onEnterFrame(e:Event):void {

    dPoint.x = stage.stageWidth - radius;
    dPoint.y = stage.stageHeight - radius;

    dFilter = new DisplacementMapFilter(map, dPoint, BitmapDataChannel.RED, BitmapDataChannel.BLUE, 100, 100, DisplacementMapFilterMode.IGNORE, 0x000000, 0);

    // The application is a displayObject itself, so just apply filters to "this"
    this.filters = [dFilter];
}

所以这段代码应该将过滤器锚定在屏幕的右下角,但不知何故,每当图像被拖走时,过滤器就会随之漂移。过滤器是否有任何理由这样做,我有什么办法可以阻止它?

4

1 回答 1

0

Dragging an image off the stage changes the size and shape of the rectangle the filter is being applied to (picture the filter as if it's taking a snapshot of everything on the stage). When the image moves off the top left, it means that (0, 0) on the filter is actually at the top left corner of the image.

If you check the bounds of the stage (in the stage's own coordinate space), you should see top and left become negative numbers when you drag an image off:

stage.getBounds(stage).top;
stage.getBounds(stage).left;

Cancelling out any negative bounds should keep your filter in the correct position:

var stageBounds:Rectangle = stage.getBounds(stage);
if (stageBounds.left < 0) {
    dPoint.x -= stageBounds.left;
}
if (stageBounds.top < 0) {
    dPoint.y -= stageBounds.top;
}
于 2013-05-20T22:54:50.540 回答