Flash像素模糊的解决方法

Flash Off Pixel

由于移动、比例变化导致Flash中DisplayObject坐标带有小数,像素出现模糊的情况经常发生,对于多层嵌套的动画尤其麻烦。以下函数遍历整个DisplayObject树,四舍五入所有对象坐标,是一个一劳永逸的解决方法。

roundChildren(this)
function roundChildren(base:DisplayObjectContainer):void {
	for (var i:int=0; i<base.numChildren-1; i++) {
		var m:DisplayObject=base.getChildAt(i) as DisplayObject;
		var p:DisplayObjectContainer=base.getChildAt(i) as DisplayObjectContainer;
		if (m) {
			m.x=Math.round(m.x);
			m.y=Math.round(m.y);
			if(p){
				if (p.numChildren>0) {
					roundChildren(p);
				}
			}
		}

	}

Tags:

categories 技术

4 条评论

  • By Daniel_z, 七月 30, 2009 @ 6:01 下午

    已经养成了坐标不带小数点的习惯~~

  • By jam, 七月 30, 2009 @ 10:36 下午

    坐标不带小数点是一项基本国策

  • By Banksy, 八月 2, 2009 @ 10:22 下午

    完全不懂~~

  • By xinyihai, 八月 7, 2009 @ 10:13 上午

    这招太狠了,不亏为神功!

Other Links to this Post

这篇文章上的评论 RSS feed TrackBack URI

留下评论

You must be logged in to post a comment.