闪光“可见”问题
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在设置
visible
和调用changed()
之间等待一帧。使用invalidateProperties()/commitProperties()
模型。Wait a frame between setting
visible
and callingchanged()
. Use theinvalidateProperties()/commitProperties()
model.