闪光“可见”问题

发布于 2024-08-29 14:16:26 字数 1186 浏览 4 评论 0原文

我正在 Flex 中编写一个工具,它可以让我使用分层位图设计复合精灵,然后将它们“烘焙”成低开销的单个位图数据。我发现了一个我无法解释的奇怪行为:切换图层的“可见”属性对每个图层都会起作用两次(即,我可以将其关闭,然后再次打开),然后再也不会对该图层起作用 -从那时起,图层保持可见。

如果我像这样覆盖图层上的“设置可见”:

override public function set visible(value:Boolean):void
    {           
        if(value == false) this.alpha = 0;
        else {this.alpha = 1;}
    }

问题就会消失,我可以根据需要切换“可见性”。有什么想法可能导致这种情况吗?

编辑:

以下是进行调用的代码:

private function onVisibleChange():void
{
            _layer.visible = layerVisible.selected;
            changed();
}

changed() 方法“烘焙”位图:

public function getBaked():BitmapData
    {
        var w:int = _composite.width + (_atmosphereOuterBlur * 2);
        var h:int = _composite.height + (_atmosphereOuterBlur * 2);
        var bmpData:BitmapData = new BitmapData(w,h,true,0x00000000);
        var matrix:Matrix = new Matrix();
        var bounds:Rectangle = this.getBounds(this);
        matrix.translate(w/2,h/2);
        bmpData.draw(this,matrix,null,null,new Rectangle(0,0,w,h),true);
        return bmpData;
    }

顺便说一句,当图层仍然可见时,使用 Flex 调试器我可以验证图层的可见值是“假”。

I'm writing a tool in Flex that lets me design composite sprites using layered bitmaps and then "bake" them into a low overhead single bitmapData. I've discovered a strange behavior I can't explain: toggling the "visible" property of my layers works twice for each layer (i.e., I can turn it off, then on again) and then never again for that layer-- the layer stays visible from that point on.

If I override "set visible" on the layer as such:

override public function set visible(value:Boolean):void
    {           
        if(value == false) this.alpha = 0;
        else {this.alpha = 1;}
    }

The problem goes away and I can toggle "visibility" as much as I want. Any ideas what might be causing this?

Edit:

Here is the code that makes the call:

private function onVisibleChange():void
{
            _layer.visible = layerVisible.selected;
            changed();
}

The changed() method "bakes" the bitmap:

public function getBaked():BitmapData
    {
        var w:int = _composite.width + (_atmosphereOuterBlur * 2);
        var h:int = _composite.height + (_atmosphereOuterBlur * 2);
        var bmpData:BitmapData = new BitmapData(w,h,true,0x00000000);
        var matrix:Matrix = new Matrix();
        var bounds:Rectangle = this.getBounds(this);
        matrix.translate(w/2,h/2);
        bmpData.draw(this,matrix,null,null,new Rectangle(0,0,w,h),true);
        return bmpData;
    }

Incidentally, while the layer is still visible, using the Flex debugger I can verify that the layer's visible value is "false".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

药祭#氼 2024-09-05 14:16:26

在设置 visible 和调用 changed() 之间等待一帧。使用 invalidateProperties()/commitProperties() 模型。

private bool _isChanged = false;
private function onVisibleChange():void
{
            _layer.visible = layerVisible.selected;
            _isChanged = true;
            invalidateProperties();
}

protected override function commitProperties():void {
    super.commitProperties();

    if (_isChanged) {
        _isChanged = false;
        changed();
    }
}

Wait a frame between setting visible and calling changed(). Use the invalidateProperties()/commitProperties() model.

private bool _isChanged = false;
private function onVisibleChange():void
{
            _layer.visible = layerVisible.selected;
            _isChanged = true;
            invalidateProperties();
}

protected override function commitProperties():void {
    super.commitProperties();

    if (_isChanged) {
        _isChanged = false;
        changed();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文